首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

ASCII码的有关问题 COM通讯

2012-01-08 
ASCII码的问题 COM通讯帮忙给检查一下如下的代码是否有问题,为何清零的ASCII码ZI在两种型号的Scale上都可

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


VB code
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


[解决办法]
建议用字节流传输
[解决办法]
看看这个,参考它
http://download.csdn.net/source/1262066
[解决办法]
探讨
引用:
看看这个,参考它
http://download.csdn.net/source/1262066


看了下,这样的调试软件我有一个了
串口调试助手 ScomAssistant v2.1

[解决办法]
没有明确的通信协议及数据帧约定,无法分析LZ的代码.

不过从LZ的Calculatescale过程代码有点疑惑,是按BCD码呢还是咋的?

你的接收代码是按Byte字节接收并转换为双字节16进制字符串,一般的称大多是按ASCII字符传递数据的.

热点排行