ASCII码的问题 COM通讯
帮忙给检查一下如下的代码是否有问题,
为何清零的ASCII码ZI在两种型号的Scale上都可以实现,但是Send Weight Value的ASCII码SI一个可以实现一个无法实现。
(Model1:MT BBA 422-3 SM Model2: MT IND425 -BB35)
Datasheet:(4.1) http://us.mt.com/us/en/home/supportive_content/product_documentation/operating_instructions.BA_IND425_USA.extFileEd.html
Private Sub InquireScale() Dim txtSum1 As String txtSum1 = "SI" & vbCrLf If Comm1.PortOpen = False Then Comm1.CommPort = Port_value Comm1.PortOpen = True End If Comm1.Output = txtSum1 'Debug.Print Comm1.OutBufferCount 'Debug.Print Comm1.InBufferCount 'Comm1.OutBufferCount = 0 '清除发送缓冲区 'Comm1.InBufferCount = 0 '清除接收缓冲区End SubPrivate Sub GetWeight_Value() On Error Resume Next Dim BytesReceived() As Byte Dim buffer As String Dim HData As String Dim i As Integer 'Select Case Comm1.CommEvent 'Case comEvReceive '接收十六进制数据。并以十六进制显示 buffer = Comm1.Input '接收数据至字符串中 BytesReceived() = buffer '将数据转入Byte数组中 'Debug.Print buffer For i = 0 To UBound(BytesReceived) '显示结果以十六进制显示 If Len(Hex(BytesReceived(i))) = 1 Then HData = HData & "0" & Hex(BytesReceived(i)) Else HData = HData & Hex(BytesReceived(i)) End If Recievedata = HData '最后将结果后入Recievedata中 'Comm1.OutBufferCount = 0 '清除发送缓冲区 'Comm1.InBufferCount = 0 '清除接收缓冲区 Comm1.PortOpen = False Next Debug.Print Recievedata '返回的19位字符串 'End Select Call Calculatescale End SubPublic Sub Calculatescale() Dim a, b, c, d, f As Integer a = Mid(Recievedata, 18, 1) b = Mid(Recievedata, 22, 1) c = Mid(Recievedata, 24, 1) d = Mid(Recievedata, 26, 1) e = Mid(Recievedata, 28, 1) If Mid(Recievedata, 15, 2) = "A0" Then Weight_value = (a * 1000 + b * 100 + c * 10 + d * 1 + e * 0.1) / 1000 Weight_value = Format(Weight_value, "0.0000") Else: Weight_value = -(a * 1000 + b * 100 + c * 10 + d * 1 + e * 0.1) / 1000 Weight_value = Format(Weight_value, "0.0000") End If 'Debug.Print Weight_value '查询的重量 单位kg Comm1.OutBufferCount = 0 '清除发送缓冲区 Comm1.InBufferCount = 0 '清除接收缓冲区End Sub