|
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
The above is to organize the data according to the sending format,
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
I have tried, if the received data length is less than 45 bytes when RThreshold=1, the results displayed in Text2.Text are all correct, and when it is greater than 45, it is wrong. |
|