Slave Address 18 Function Code 03 Start Address (Hi) 0B Start Address (Lo) B9 Number of points (Hi) 00 Number of points (Lo) 01 CRC (Lo) 55 CRC (Hi) C2
TxMsg$ = CHR$(&H18)+CHR$(&H03)+CHR$(&H0B)+CHR$(&HB9)+CHR$(&H00)+CHR$(&H01)
TxMsg$ = TxMsg$ + CrcStr(TxMsg$)
IF CrcStr(RxMsg$) = CHR$(0) + CHR$(0) THEN ' CRC is OK ' Process the response ELSE ' Bad CRC - do nothing - don't respond END IF
FUNCTION CrcStr(a$) AS STRING LOCAL ErrorWord% = &HFFFF, n, j, LSB AS INTEGER FOR n = 1 TO LEN(A$) ByteVal = ASC(MID$(a$, n, 1)) ErrorWord% = (ErrorWord% AND &HFFFF) XOR ASC(MID$(a$, n, 1)) FOR j = 1 TO 8 LSB = ErrorWord% AND &H0001 IF LSB = 1 THEN ErrorWord% = ErrorWord% - 1 ErrorWord% = ErrorWord% / 2 IF LSB = 1 THEN ErrorWord% = ErrorWord% XOR &HA001 NEXT j NEXT n CrcStr = CHR$(ErrorWord% AND &HFF) + CHR$(ErrorWord% >> 8) END FUNCTION