7-5
Chapter 7. CPL COMMUNICATION FUNCTION
• How to calculate a checksum
(1) Add the character codes in the message from STX through ETX in single
byte units.
(2) Take two's complement of the low-order one byte of the addition result.
(3) Convert the obtained two's complement to a two-byte ASCII code.
The following is a sample checksum calculation:
[Sample message]
STX: 02H
'0': 30H (1st byte of the station address)
'1': 31H (2nd byte of the station address)
'0': 30H (1st byte of the sub-address)
'0': 30H (2nd byte of the sub-address)
'X': 58H (device code)
'R': 52H (1st byte of the command)
'S': 53H (2nd byte of the command)
',': 2CH (3rd byte of the command)
'1': 31H (4th byte of the command)
'5': 35H (5th byte of the command)
'0': 30H (6th byte of the command)
'1': 31H (7th byte of the command)
'W': 57H (8th byte of the command)
',': 2CH (9th byte of the command)
'1': 31H (10th byte of the command)
(omitted)
ETX: 03H
(1) Add the character codes in the message from STX through ETX in single
byte units.
The add operation in single byte units is as follows:
02H + 30H + 31H + 30H + 30H + 58H + 52H + 53H + • • • + 03H.
Assume that the result is 376H.
(2) The low-order one byte of the addition result 376H is 76H. The two's
complement of 76H is 8AH.
(3) Convert the obtained 8AH to a two-byte ASCII code.
The result is:
'8': 38H
'A': 41H,
and the two bytes, '8'(38H) and 'A'(41H), are the checksum.
• Delimiter (CR/LF)
This indicates the end of the message. Immediately after LF is received, the
device enters a state allowed to process the received message