Ppendix B: Lrc Generation; Ppendix C: Crc Generation - KROHNE ALTOSONIC V Guide De Référence

Masquer les pouces Voir aussi pour ALTOSONIC V:
Table des Matières

Publicité

9.2
Appendix B: LRC Generation
(As taken from the website: www.modicon.com/techpubs/crc7.html)
The Longitudinal Redundancy Check (LRC) field is one byte, containing an eight-bit binary value. The LRC
value is calculated by the transmitting device, which appends the LRC to the message. The receiving
device recalculates an LRC during receipt of the message, and compares the calculated value to the actual
value it received in the LRC field. If the two values are not equal, an error results.
The LRC is calculated by adding together successive eight-bit bytes in the message, discarding any
carries, then two's complementing the result. The LRC is an eight-bit field, therefore each new addition of a
character that would result in a value higher than 255 decimal simply rolls over the field's value through
zero. Because there is no ninth bit, the carry is discarded automatically.
Generating an LRC
Step 1 :
Add all bytes in the message, excluding the starting colon and ending CRLF. Add them into an eight-bit
field, so that carries will be discarded.
Step 2
Subtract the final field value from FF hex (all 1's), to produce the ones-complement.
Step 3
Add 1 to produce the two's-complement.
Placing the LRC into the Message
When the the eight-bit LRC (two ASCII characters) is transmitted in the message, the high order character
will be transmitted first, followed by the low order character-e.g., if the LRC value is 61 hex (0110 0001):
Figure 8 LRC Character Sequence
Example
An example of a C language function performing LRC generation is shown below.
The function takes two arguments:
unsigned char *auchMsg ;
unsigned short usDataLen ;
LRC Generation Function
static unsigned char LRC(auchMsg, usDataLen)
unsigned char *auchMsg ;
unsigned short usDataLen ;
{
unsigned char uchLRC = 0 ;
while (usDataLen--)
uchLRC += *auchMsg++ ;
return ((unsigned char)(-((char_uchLRC))) ;
}
9.3
Appendix C: CRC generation
(As taken from the website: www.modicon.com/techpubs/crc7.html)
The Cyclical Redundancy Check (CRC) field is two bytes, containing a 16-bit binary value. The CRC value
is calculated by the transmitting device, which appends the CRC to the message. The receiving device
recalculates a CRC during receipt of the message, and compares the calculated value to the actual value it
received in the CRC field. If the two values are not equal, an error results.
ALTOSONIC V
A pointer to the message buffer containing binary data to be used for generating the LRC
The quantity of bytes in the message buffer. The function returns the LRC as a type unsigned char.
/* message to calculate */
/* LRC upon quantity of */
/* bytes in message
/* LRC char initialized */
/* pass through message */
/* buffer add buffer byte*/
/* without carry
/* return twos complemen */
Manuel Modbus
*/
*/
Page 51 sur 55

Publicité

Table des Matières
loading

Ce manuel est également adapté pour:

Modbus

Table des Matières