Typical Crc-16 Calculation Program In Quick Basic; Typical Crc-16 Calculation Program In C; No Response Message - YASKAWA F7 User Manual

Hide thumbs Also See for F7:
Table of Contents

Advertisement

http://www.aotewell.com

Typical CRC-16 Calculation Program in Quick Basic

crcsum# = &HFFFF&
crcshift# = &H0&
crcconst# = &HA001&
CLS
PRINT "*********************************************"
PRINT
PRINT "
PRINT
PRINT "*********************************************"
PRINT "If entering data in hex, precede 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 byte7) 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&)

Typical CRC-16 Calculation Program in C

// *buf
pointer to character array that contains the characters used to calculate CRC
// bufLen
number of characters to calculate CRC for
// *crc
pointer to the array that contains the calculated CRC
void
getMBCRC(cahr *buf, int bufLen, char *crc) {
unsigned long crc_0 = 0xffff;
unsigned long crc_1 = 0x0000;
int i,j;
for (i=0; i<bufLen; i++) {
crc_0 ^= ((unsigned long)buf[i] & 0x0ff);
for (j=0;j<8;j++){
crc_1 = (crc_0 >> 1) & 0x7fff;
if (crc_0 & 0x0001)
crc_0 = (crc_1 ^ 0xa001);
else
crc_0 = crc_1;
}
crc[0] = (unsigned char)((crc_0/256) & 0x00ff);
crc[1] = (unsigned char)((crc_0 & 0x00ff);
return;
}

No Response Message

The Drive disregards the command message and does not return the response message in the following cases:
1. In simultaneous broadcasting of data (slave address field is 0), all slaves execute but do not respond.
2. When a communication error (overrun, framing, parity, or CRC-16) is detected in the command message.
3. When the slave address in the command message does not coincide with the address set in the slave.
4. When the command message data length is not proper.
Tel: +(86) 755 8660 6182
CRC-16 Calculator
}
Aotewell
"
// Declare and initialize variables
// Loop through characters of input array
// XOR current character with 0x00ff
// Loop through character bits
// Shift result right one place and store
// if pre-shifted value bit 0 is set
// XOR the shifted value with 0xa001
// if pre-shifted value bit 0 is not set
// set the pre-shifted value equal to the shifted value
//
Hi byte
//
Lo byte
Communications D - 7
Aotewell
Email: Sales@aotewell.com
http://www.aotewell.com

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents