ā 75 ā
8
Chapter
' Sending the command. ***********************************************************************
' Creating CRC for Send Data
GoSub 10000 ' CRC computation
Txdat(Txsu + 1) = CRC1 '
Txdat(Txsu + 2) = CRC2 '
' Send the created command.
MSComm1.Output = Txdat ' Send one byte
' Wait until all of the response data is sent.
Start = Timer ' Saves the waiting start time.
Do While Timer < Start + PauseTime ' Has the set wait time passed?
DoEvents ' Passes control to other processes.
If ((Start + PauseTime) - Timer) > PauseTime Then
Start = Timer
End If
Loop
MSComm1.PortOpen = False ' COM port close
Write_command.Enabled = True
Exit Sub
' ********************************************************************************************
10000 ' CRC calculation subroutine IN:Txdat(Txsu) / OUT CRC1,CRC2 **************************
CRC = &HFFFF
For i = 0 To Txsu Step 1
CRC = CRC Xor Txdat(i)
For J = 1 To 8 Step 1
CT = CRC And &H1
If CRC < 0 Then CH = 1 Else: CH = 0: GoTo 11000
CRC = CRC And &H7FFF
11000 CRC = Int(CRC / 2)
If CH = 1 Then CRC = CRC Or &H4000
If CT = 1 Then CRC = CRC Xor &HA001
Next J
Next i
CRC1 = CRC And &HFF
CRC2 = ((CRC And &HFF00) / 256 And &HFF)
Return
End Sub