发表于:2005/4/11 9:43:00
#0楼
问个关于MODBUS通讯的接受问题
现在我数据能传给下位机了,下位机也能收到并给回答了,但是上位机收到的数据由于ascⅡ的限制只能传128前的数据,以后的数据80开始我收到的会溢出显示3F。。还有就是我收到的CRC也是这样,而且要是CRC大于80的话,会显示00,程序会有个停顿,不知道为什么。。。
请发EMAIL给我
summer_sunjie@sina.com
部分源代码在这里
Private Sub Hexsent()
Stxt.Text = txtSend + RTUCRC
Dim hexchrlen%, hexchr As String, hexcyc%, hexmid As String
Dim i, j As Integer
hexchrlen = Len(Stxt)
For hexcyc = 1 To hexchrlen 'hexcyc=1to16
hexchr = Mid(Stxt, hexcyc, 1)
If InStr("0123456789ABCDEFabcdef", hexchr) = 0 Then
MsgBox "ÎÞЧµÄÊýÖµ£¬ÇëÖØÐÂÊäÈë", , "´íÎóÐÅÏ¢"
Exit Sub
End If
Next
ReDim outbyte(1 To hexchrlen / 2) As Byte
For i = 1 To hexchrlen / 2
hexcyc = 2 * i - 1
hexchr = Mid(Stxt, hexcyc, 2)
hexmid = CStr(hexchr)
outbyte(i) = Val("&H" + hexmid)
Next i
ctrMSComm.Output = outbyte()
End Sub
' hexstring = ctrMSComm.Input
' i = Len(hexstring)
' For j = 1 To i
' hexchr = Mid(hexstring, j, 1)
' If Hex(Asc(hexchr)) < 16 Then
' txtReceive.Text = txtReceive.Text & "0" & Hex(Asc(hexchr)) & " "
' Else
' txtReceive.Text = txtReceive.Text & Hex(Asc(hexchr)) & " "
' End If
''txtReceive.Text = txtReceive.Text & ctrMSComm.Input & CStr(Chr(13)) & CStr(Chr(10))
' Next j
现在我数据能传给下位机了,下位机也能收到并给回答了,但是上位机收到的数据由于ascⅡ的限制只能传128前的数据,以后的数据80开始我收到的会溢出显示3F。。还有就是我收到的CRC也是这样,而且要是CRC大于80的话,会显示00,程序会有个停顿,不知道为什么。。。
请发EMAIL给我
summer_sunjie@sina.com
部分源代码在这里
Private Sub Hexsent()
Stxt.Text = txtSend + RTUCRC
Dim hexchrlen%, hexchr As String, hexcyc%, hexmid As String
Dim i, j As Integer
hexchrlen = Len(Stxt)
For hexcyc = 1 To hexchrlen 'hexcyc=1to16
hexchr = Mid(Stxt, hexcyc, 1)
If InStr("0123456789ABCDEFabcdef", hexchr) = 0 Then
MsgBox "ÎÞЧµÄÊýÖµ£¬ÇëÖØÐÂÊäÈë", , "´íÎóÐÅÏ¢"
Exit Sub
End If
Next
ReDim outbyte(1 To hexchrlen / 2) As Byte
For i = 1 To hexchrlen / 2
hexcyc = 2 * i - 1
hexchr = Mid(Stxt, hexcyc, 2)
hexmid = CStr(hexchr)
outbyte(i) = Val("&H" + hexmid)
Next i
ctrMSComm.Output = outbyte()
End Sub
' hexstring = ctrMSComm.Input
' i = Len(hexstring)
' For j = 1 To i
' hexchr = Mid(hexstring, j, 1)
' If Hex(Asc(hexchr)) < 16 Then
' txtReceive.Text = txtReceive.Text & "0" & Hex(Asc(hexchr)) & " "
' Else
' txtReceive.Text = txtReceive.Text & Hex(Asc(hexchr)) & " "
' End If
''txtReceive.Text = txtReceive.Text & ctrMSComm.Input & CStr(Chr(13)) & CStr(Chr(10))
' Next j