12.07.2015 Views

Series 2000 Communications Handbook - Soliton

Series 2000 Communications Handbook - Soliton

Series 2000 Communications Handbook - Soliton

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

MODBUS and JBUS Protocol<strong>Series</strong> <strong>2000</strong> <strong>Communications</strong> <strong>Handbook</strong>3.11. EXAMPLE OF A CRC CALCULATION IN BASICLANGUAGEFunction CRC(message$) as long'' CRC runs cyclic Redundancy Check Algorithm on input message$'' Returns value of 16 bit CRC after completion and'' always adds 2 crc bytes to message'' returns 0 if incoming message has correct CRC'' Must use double word for CRC and decimal constantscrc16& = 65535FOR c% = 1 to LEN(message$)crc16& = crc16& XOR ASC(MID$(message$, c%, 1))FOR bit% = 1 to 8IF crc16& MOD 2 THENcrc16& = (crc16& \ 2) XOR 40961ELSEcrc16& = crc16& \ 2END IFNEXT BIT%NEXT c%crch% = CRC16& \ 256: crcl% = CRC16& MOD 256message$ = message$ + CHR$(crcl%) + CHR$(crch%)CRC = CRC16&END FUNCTION CRC3-12 <strong>Series</strong> <strong>2000</strong> <strong>Communications</strong> <strong>Handbook</strong> Part No HA026230 Issue 2.0 Feb-00

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!