
23
APPENDIX A
CALCULATION OF THE CHECKSUM
In this appendix some examples of function in the C language cal-
culating the LRC checksum for ASCII mode and the CRC
checksum for the RTU mode have been shown.
The function for LRC calculation has two arguments:
unsigned char *outMsg;
Pointer for the communication buffer,
including binary data from which one
must calculate LRC.
unsigned short usDataLen;
Number of bytes in the
communication buffer.
The function returns LRC of
unsigned char type
.
static unsigned char LRC(outMsg, usDataLen)
unsigned char *outMsg; /* buffer to calculate LRC */
unsigned short usDataLen;
/* number of bytes in the buffer */
{
unsigned char uchLRC = 0;
/* initialization of LRC */
while (usDataLen- -)
= *+; /* add the buffer byte without transfer */
return ((unsigned char)(-(char uchLRC)));
/* return the sum
in the completion
code up two */
}
An example of function in C language calculating the CRC sum is
presented below. All possible values of CRC sum are placed in two
tables.
The first table includes the highest byte of all 256 possible values of
the 16-bit CRC field, however the second table includes the lowest
byte.
Содержание RE15
Страница 1: ...1 USER S MANUAL SERIAL INTERFACE WITH MODBUS PROTOCOL MICROPROCESSOR CONTROLLER RE15...
Страница 2: ...2...
Страница 27: ...27...