Hello everybody, I’m trying to calculate the LRC on some numbers from a Drive. I’ll give an example:
Here is one, this is completed: 3a 31 31 30 36 30 37 30 30 30 30 39 36 34 43 0d 0a
34 43 is the calculated LRC value for that string where 00 0a are CR, LF
I have not been able to get this worked out, I can get the Single LRC but hats it.
Anybody know anything about this?
PS.
Here is the code in c that was provided to me to do this with, but it looks Greek to me.
static char tmModbus_CheckASCII_LRC( unsigned char *src, int data_num )
{
int i;
unsigned char lrc_calculation = 0; // LRC from calculated data
unsigned char lrc_rceived = 0; // LRC from the buffer directly
unsigned char result;
for ( i = 0; i < ( data_num - 5 ) / 2; i++ ) {
lrc_calculation += tmModbus_ASCII2UNCHAR( src[ 1 +i * 2 ], src[ 2 + i * 2 ] );
}
lrc_rceived = tmModbus_ASCII2UNCHAR( src[ data_num - 4 ], src[ data_num - 3 ] );
result = ( lrc_calculation + lrc_rceived ) & 0xFF;
if( result == 0 ){
return 1;
}else{
return 0;
}
}