Java Modbus Checksum (LRC) issue

Thread Starter

jamespshan

Joined Oct 3, 2012
2
Hi,

I am trying to get existing java code to communicate with a device through a serial port using net.wimpi.modbus java libraries and ascii encoding.

My problem is I believe that the LRC checksum value being generated from the modbus java libraries appear to be incorrect but I cannot find where this occurs or see any means of influencing it.

The packet I am sending is :320300010054
I'm told the correct LRC value to be appended for this is AE however if I snoop on the serial port data I see that the java application is sending 76.

If I use use a third party tool to send the correct packet :)320300010054A4) it receives the correct response.
Does anyone know how I can fix this?

Below is some sample code which I cam using. The red text in bold (trans.execute(); ) is where the packet is sent.

Any help is greatly apppreciated.

Thanks

Jim

Rich (BB code):
   SerialParameters params=new SerialParameters();
   params.setPortName("COM1");
   params.setBaudRate(9600);
   params.setParity("Even");
   params.setEncoding("ascii");
   params.setReceiveTimeout(3000);
        
   SerialConnection con = con = new SerialConnection(params);
   try {
     con.open();
   }
   catch (Exception e) {
       throw new IOException("Problem opening serial port");
   }    
   try {
        con.getSerialPort().enableReceiveTimeout(SERIAL_RECEIVE_TIMEOUT);
   }
    catch (UnsupportedCommOperationException e) { throw new    IOException("Failed to set serial port timeout of " + SERIAL_RECEIVE_TIMEOUT + "ms");
}
   ModbusRequest req = new ReadMultipleRegistersRequest(1, 84);
   req.setUnitID(50);
   req.setHeadless();
   req.setHeadless();
    
   ModbusTransaction trans = new ModbusSerialTransaction(con);
   trans.setRequest(req);
   trans.execute();
   ModbusResponse response = trans.getResponse();
 
Last edited by a moderator:

Thread Starter

jamespshan

Joined Oct 3, 2012
2
Ok, so I removed the jarmod jar file reference from my project and unpacked the full source code into my project instead. This give me the visibility into the checksum calculation performed in ModbusUtil.java that I couldn't see before.

The method seems correct which leads me to believe that the device Im communicating with via modbus contains a bug or custom LRC calculation.

I will take this up with the engineer but for now my immediate issue was solved by applying the original source code to the project in place of the jamod library.
 
Top