F - checksum calculations, Checksum description, Checksum basic program – Rockwell Automation 2706-F11J_F11JC_F21J_F21JC DL50 INSTALLATION MANUAL User Manual

Page 120: Checksum calculations

Advertising
background image

A–B

F

Appendix

F–1

Checksum Calculations

The checksum bytes verify the transmission of data when the DL50 is in the
duplex mode. There are three bytes, the first byte is a dummy byte and the
other two are checksum bytes. If either of the two checksum bytes contain a
value equivalent to a CR (decimal 13) or DC2 (decimal 18), the content of
the dummy byte is adjusted to alter the value of the checksum. The dummy
byte is adjusted by:

Adding a value of 1 if the least significant
checksum byte = 13 or 18 (decimal)

Adding a value of 128 or 255 (decimal) if the
most significant byte = 13 or 18 (decimal)

This example calculates the checksum bytes for Example #2 (using Duplex
Protocol) on page 6.3. Modify this program to calculate checksums for other
messages.

1 REM

Initialize constants:

2 True=1:False=0
10 REM:

Example program to calculate the checksum for a

11 REM:

message packet to be sent to the DL50

20 REM
30 MSG$=CHR$(2)+“Motor ON”
31 REM

<ctrl>B + Message_String

32 REM

The address=255, Line No.=1, Message Attributes = 165,200,128

33 REM

The dummy byte initially = 0

34 REM
35 DUMMY = 0
36 TMP1$=MSG$+CHR$(255)+CHR$(1)+CHR$(13)+CHR$(165)+CHR$(200)+CHR$(128)+CHR$(DUMMY)
38 REM
39 REM

Get the length of the message packet string, TMP1$

40 L=LEN(TMP1$)
50 REM

Start with 0, and add the ASCII value of each character in the string

55 BCNT=0
60 FOR P=1 to L
70 BCNT=BCNT+ASC(MID$(TMP1$, P, 1))
75 NEXT P
80 REM

Separate out the most and least significant bytes

85 MSB%=(BCNT–(BCNT MOD 256))/256
90 LSB%=BCNT AND 255
92 REM

Look for bad checksum bytes (values 13 or 18)

93 BAD=FALSE
95 IF (LSB%=13) OR (LSB%=18) THEN DUMMY = (DUMMY+1) MOD 255:BAD=TRUE
96 IF (MSB%=13) OR (MSB$=18) THEN DUMMY = (DUMMY + 127) MOD 256:BAD=TRUE
99 REM

lines 99 and 100 for program test only

100 PRINT “MSB=”;MSB%,“LSB=”;LSB%,“dummy=”;DUMMY
101 IF BAD GOTO 36
199 REM

lines 199 and 200 for program test only

200 PRINT “Two Byte Checksum=”;BCNT

Checksum Description

Checksum BASIC Program

Advertising