高手帮忙!关于MSCOMM接收问题!急啊!
我用VB写了一个关于MODBUS的协议
可是在接收时产生了问题
我用的是MSComm1_OnComm事件接受的,代码如下:
Dim nowstring As Variant
Dim i As Integer
Select Case MSComm1.CommEvent
Case comEvReceive '接收事件
'接收缓冲区收到Rthreshold个字符时触发
If MSComm1.InBufferCount Then
nowstring = MSComm1.Input
For i = LBound(nowstring) To UBound(nowstring)
InString = InString & CStr(Hex(Val(nowstring(i)))) & " "
Next i
nowstring = ""
end if
比如我发送的数据是 01 04 00 00 00 10 F1 C6
接收的数据应该为01 04 20 04 B2 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 B1 1B
可是有时这个数据接收过来是正确的,有时只接受到01 04 20 04 B2 00 00 00
怎样才能正确接收啊?
我设置的MSCOMM的属性为
MSComm1.Settings = "19200,8,N,1"
MSComm1.CommPort =1
MSComm1.SThreshold = 1
MSComm1.RThreshold = 1
MSComm1.InputLen = 0
MSComm1.PortOpen=true
MSComm1.InputMode = comInputModeBinary
请各位大侠帮忙啊!在下不胜感激!