calculating lrc of messages lrc value of message used check if characters of message received in same way sent. how calculate value of lrc “00c1” , check value of “00d1” messages regularly issue presented ccv. below shortly describe lrc calculating , check method.
example lrc calculation: /********************************************************************* * module name : com_get_lrc * -------------------------------------------------------------------- * interface : uchar com_get_lrc( uchar *, word ) * * parameters : uchar *source - buffer calc lrc on word * length - number of bytes of source * * return value : uchar lrc - result lrc * * globals : none * * locals : uchar lrc - calculate lrc * * description : function calculate lrc on source * buffer. lrc start value 0x00 , * xored each character of buffer. * **********************************************************************/`enter * * uchar com_get_lrc(uchar *source,word length) * { * uchar lrc = 0x00; * while( length-- ) * { * lrc = lrc bitxor *(source)++; * } * return( lrc ); * }
how can convert c#?
no need give length, c# knows length of array. can aggregate results lambda function return bitwise xor of bytes in array.
using system.linq; //... public static byte getlrc(byte[] data) { return data.aggregate((a, b) => (byte)(a ^ b)); }
Comments
Post a Comment