Lrc Generation - Chauvin Arnoux ULYS FLEX Modbus Notice De Fonctionnement

Table des Matières

Publicité

Les langues disponibles

Les langues disponibles

1.1 LRC GENERATION

The Longitudinal Redundancy Check (LRC) field is one byte, containing an 8–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
8–bit bytes in the message, discarding any carries, and then two's complementing the result. The LRC is an 8–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.
A procedure for generating an LRC is:
1. Add all bytes in the message, excluding the starting 'colon' and ending CR LF. Add them into an 8–bit
field, so that carries will be discarded.
2. Subtract the final field value from $FF, to produce the ones–complement.
3. Add 1 to produce the twos–complement.
PLACING THE LRC INTO THE MESSAGE
When the the 8–bit LRC (2 ASCII characters) is transmitted in the message, the high–order character will be
transmitted first, followed by the low–order character. For example, if the LRC value is $52 (0101 0010):
Colon
Addr
':'
C-FUNCTION TO CALCULATE LRC
*pucFrame – pointer on "Addr" of message
usLen – length message from "Addr" to end "Data"
UCHAR prvucMBLRC( UCHAR * pucFrame, USHORT usLen )
{
UCHAR
while( usLen-- )
{
ucLRC += *pucFrame++;
}
/* Return twos complement */
ucLRC = ( UCHAR ) ( -( ( CHAR ) ucLRC ) );
return ucLRC;
}
40
Func
Data
Data
Data
Count
ucLRC = 0;
/* LRC char initialized */
/* Add buffer byte without carry */
....
Data
LRC
LRC
Hi '5'
Lo'2'
CR
LF
MODBUS RTU/ASCII

Publicité

Table des Matières
loading

Table des Matières