Yaskawa GPD 515-G5 Modbus RTU User Manual
Page 34

6-14 The Message Format
Typical CRC-16 Calculation Program in Quick Basic:
crcsum# = &HFFFF&
crcshift# = &H0&
crcconst# = &HA001&
CLS
PRINT "***************************************************"
PRINT
PRINT " CRC-16 calculator"
PRINT
PRINT "***************************************************"
PRINT "If entering data in hex, preceed the data with '&H'"
PRINT " Example: 32decimal = 20hex = &H20"
PRINT "***************************************************"
PRINT
INPUT "Enter the number of bytes in the message: ", maxbyte
FOR bytenum = 1 TO maxbyte STEP 1
 PRINT "Enter byte "; bytenum; ":":
 INPUT byte&
 byte& = byte& AND &HFF&
 crcsum# = (crcsum# XOR byte&) AND &HFFFF&
 FOR shift = 1 TO 8 STEP 1
 crcshift# = (INT(crcsum# / 2)) AND &H7FFF&
 IF crcsum# AND &H1& THEN
 crcsum# = crcshift# XOR crcconst#
 ELSE
 crcsum# = crcshift#
 END IF
 NEXT shift
NEXT bytenum
lower& = crcsum# AND &HFF&
upper& = (INT(crcsum# / 256)) AND &HFF&
PRINT "Lower byte (1st) = ", HEX$(lower&)
PRINT "Upper byte (2nd) = ", HEX$(upper&)
