how to calculate longitudinal redundancy check (LRC) for Modbus ASCII in java?
I want to calculate LRC for Modbus ascii protocol using java. I have searched for the solutions online but haven't found any.
I used this online lrc calculator to calculate lrc http://www.metools.info/encoding/ecod127.html
I just found this one solution on StackOverflow here is that How can I calculate Longitudinal Redundancy Check (LRC)?
byte[] byte = {31, 30, 31, 30, 31, 31}
public static byte calculateLRC(byte[] bytes)
{
int LRC = 0;
for (int i = 0; i < bytes.Length; i++)
{
LRC -= bytes[i];
}
return (byte)LRC;
}
As expected the LRC I should get is "DC" but I'm getting 72 as output.
Does anyone know how to calculate LRC for modbus ascii protocol. Thanks in advance :)