ā 71 ā
8
Chapter
' Import the response data into a byte array.
MSComm1.InputMode = comInputModeBinary ' Set binary mode
length = MSComm1.InBufferCount ' Retrieve the no. of sent data bytes
MSComm1.InputLen = 0 ' Set retrieval of all data
Rxbuff = MSComm1.Input ' Import received data into the received buffer
Ansdat = Rxbuff ' Assign received data into the byte array
' Calculating CRC for Received Data
Ansu = length - 3 ' Received data length
GoSub 20000 ' CRC computation
' Error check
If (length = 0) Then ' No answer
Noans = Noans + 1: Rx_data.Caption = "Noans": GoTo 150'
ElseIf ((Ansdat(length - 2) <> CRC1) + (Ansdat(length - 1) <> CRC2)) Then ' CRC error
CRCErr = CRCErr + 1: Rx_data.Caption = "CRCErr": GoTo 150
ElseIf Ansdat(1) >= &H80 Then ' Command error
CMDErr = CMDErr + 1: Rx_data.Caption = "CMDErr": GoTo 150
End If
' Processing correctly received data
wrk1 = Ansdat(3)
wrk2 = Ansdat(4)
wrk3 = Ansdat(5)
wrk4 = Ansdat(6)
If Ansdat(5) > 128 Then ' Received data minus time
Rx_data.Caption = Str(((wrk3 * (2 ^ 24)) + (wrk4 * (2 ^ 16)) + (wrk1 * (2 ^ 8)) + wrk2) - (2 ^ 32))
Else
Rx_data.Caption = Str(((wrk3 * (2 ^ 24)) + (wrk4 * (2 ^ 16)) + (wrk1 * (2 ^ 8)) + wrk2))
End If
150
MSComm1.PortOpen = False ' COM port close
TX1.Enabled = True
Exit Sub