56
4-3-5 Frame Checksum (FCS) Calculation
The frame checksum is an 8-bit value converted into two ASCII characters. The
8-bit value is the result of an EXCLUSIVE OR sequentially performed between
each character in a transmission, from the first character in the frame to the last
character of the text in that frame.
@ 10 RR 0000001 42 * CR
@ 0100 0000
XOR
1 0011 0001
XOR
0 0011 0000
XOR
R 0101 0010
1 0011 0001
Result 0100 0010
↓↓
42
Example
Converted to hexadecimal
and treated as ASCII
Node
No.
Header Text FCS Termi-
nator
FCS Calculation Program The following program is an example of how frame checksum calculations can
be performed on received data.
400 ∗FCSCHECK
405 L=LEN(RESPONSE$) Transmit/receive data. . . . . . . . . . . . . . . . . . . . .
410 Q=0:FCSCK$=” ”
415 A$=RIGHTS$(RESPONSE$, 1)
417 PRINT RESPONSE$, A$, L
420 IF A$=”∗” THEN LENGS=LEN(RESPONSE$)–3 ELSE LENGS=LEN(RESPONSE$)–2
430 FCSP$=MID$(RESPONSE$, LENGS+1, 2) Receive FCS data
440 FOR I=1 TO LENGS Number of characters in FCS calculation range.. . . . . . . . . . . . . . . . . . . . .
450 Q=ASC(MID$(RESPONSE$, I, 1)) XOR Q
460 NEXT I
470 FCSD$=HEX$(Q) FCS calculation result. . . . . . . . . . . . . . . . . . . . . . . . .
480 IF LEN(FCSD$)=1 THEN FCSD$=”0”+FCSD$
490 IF FCSD$<>FCSP$ THEN FCSCK$=”ERR”
495 PRINT ”FCSD$=”;FCSD$, ”FCSP$=”;FCSP$, ”FCSCK$=”;FCSCK$
500 RETURN
Note 1. Received data contains an FCS, delimiter/terminator, etc. If the data is not
received normally, however, any of these parts may be missing or corrupted.
Be sure to allow for the possibility of missing or corrupted data when receiv-
ing data at the host.
2. In this example, the code for CR (CHR$ (13)) is not included in RE-
SPONSE$. Modify lines 415 and 420 to include the code for CR.
C-mode Commands Section 4-3