|
楼主 |
发表于 2020-7-28 08:45:01
|
显示全部楼层
Private Sub Form_Load()
MSComm1.SThreshold = 0
MSComm1.RThreshold = 1
MSComm1.Settings = "19200,e,7,1"
MSComm1.CommPort = 1
MSComm1.PortOpen = True
Timer1.Interval = 5000
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Timer1.Enabled = False
str = "04" + "51" + Hex(&H1C00 + 510 * 2) + "0A" + Chr(3)
ChkSum = 0
For i = 1 To Len(str)
ChkSum = ChkSum + Asc(Mid$(str, i, 1))
Next i
str = Chr(2) + str + Right(Hex(ChkSum), 2)
MSComm1.Output = str
end sub
上面是根据发送格式,整理数据,
Private Sub MSComm1_OnComm()
If MSComm1.CommEvent = comEvReceive Then
Timer1.Interval = 5000
Timer1.Enabled = True
Text2.Text = 0
Text2.Text = MSC1.Input
end if
End Sub
我试过了,如果接收到的数据长度小玩45个字节RThreshold=1 时,Text2.Text中显示的结果都是是对的,大于45时,就是错的, |
|