Message Formats 2-14
►
CRC-16 Calculation Example - C
void
getMBCRC(char *, int, char *)
// function prototype
void
getMBCRC(char *buf, int bufLen, char *crc) { // Function name and parameter list returning a void
// *buf
pointer to character array used to calculate CRC
// bufLen
number of characters to calculate CRC for
// *crc
pointer to the array that contains the calculated CRC
unsigned long crc_0 = 0xffff;
// Declare and initialize variables
unsigned long crc_1 = 0x0000;
// Declare and initialize variables
int
i,j;
//
Declare
and
initialize
variables
for (i=0; i<bufLen; i++) {
// Loop through characters of input array
crc_0 ^= ((unsigned long)buf[i] & 0x00ff);
// XOR current character with 0x00ff
for (j=0;j<8;j++) {
// Loop through characters bits
crc_1 = (crc_0 >> 1) & 0x7fff;
// shift result right one place and store
if (crc_0 & 0x0001)
// if pre-shifted value bit 0 is set
crc_0 = (crc_1 ^ 0xa001);
// XOR the shifted value with 0xa001
else
// if pre-shifted value bit 0 is not set
crc_0 = crc_1;
// set the pre-shifted value equal to the shifted value
}
// End for loop - Loop through characters bits
}
// End for loop - Loop through characters of input array
crc[0] = (unsigned char)((crc_0/256) & 0x00ff);
// Hi byte
crc[1] = (unsigned char)(crc_0 & 0x00ff);
// Lo byte
return;
//
Return
to
calling
function
} //
End
of
CRC
calculation
function
Figure 2.2 – CRC-16 Calculation in C
Содержание CIMR-E7U Series
Страница 1: ...E7 Drive Parameter Access Technical Manual Drive Models CIMR E7U Document Number TM E7 11...
Страница 2: ......
Страница 6: ...iv This page intentionally left blank...
Страница 8: ...Connections 1 2 This page intentionally left blank...
Страница 10: ...Connections 1 4 This page intentionally left blank...
Страница 19: ...Connections 1 13 This page intentionally left blank...
Страница 21: ...Message Formats 2 2 This page intentionally left blank...
Страница 35: ...Troubleshooting 3 2 This page intentionally left blank...
Страница 43: ...Troubleshooting 3 10 This page intentionally left blank...
Страница 45: ...E7 Drive Parameters 4 2 This page intentionally left blank...
Страница 71: ...E7 Drive Parameters 4 28 This page intentionally left blank...
Страница 73: ...User Notes 5 3 This page intentionally left blank...
Страница 81: ...User Notes 5 11 Notes Enter the current application parameter data and any relevant notes...