
10
2.4.2 Visual Basic Calculate CRC16 example
Function CRC16(String As String) As String
Dim N As Integer, i As Integer, NByte As Integer
Dim CRC As Long, a As Byte
Dim Buffer As String
NByte = Len(String)
CRC = 65535
For i = 1 To NByte
a = Asc(Mid$(String, i, 1)) 'C(I)
CRC = (CRC Xor a) And &HFFFF
For N = 0 To 7
If CRC And 1 Then
CRC = (CRC \ 2)
CRC = (CRC Xor 40961)
Else
CRC = CRC \ 2
End If
Next
Next
Buffer = Right$("0000" + Hex$(CRC And &HFFFF), 4)
CRC16 = Chr$("&H" + Right$(Buffer, 2)) + Chr$("&H" + Left$(Buffer, 2))
End Function
2.5 Message Synchronisation
Message synchronisation between the transmitter and the receiver is
obtained by inserting a pause of at least 3.5 times the time of one
character between the messages. If the receiving device does not
receive for the time required for 3 characters, it considers the previous
message completed and concludes that the next byte received will be the
first of a new message and, consequently, an address.
3. The MODBUS Functions
This section provides a detailed description of the MODBUS functions
implemented on ATHENA CONTROLS instruments.
3.1 Read Output Status (01)
This function is used for requesting the ON or OFF status of binary
logical variables. Broadcast mode is not allowed.
Question
In addition to the address of the slave and the function code (01), the
message contains the starting address expressed in two bytes and the
number of bits to be read, also occupying two bytes. Address numbering
starts from zero (bit1 = 0) for MODBUS, or one (bit1 = 1) for JBUS.
Comentários a estes Manuais