Menu

Checksum LRC Problem

jimbo
2012-10-04
2013-05-28
  • jimbo

    jimbo - 2012-10-04

    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

    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_RE CEIVE_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();

     
  • jimbo

    jimbo - 2012-10-04

    Hi,

    I've found the source code for ModbusASCIITransport.java online and I can see that there is some methods here for LRC calculation. Can someone tell me if this its possible to debug through this code or see if or how its being used?

    Thanks

     
  • jimbo

    jimbo - 2012-10-04

    Ok. Im learning! I've removed the jamod library from my project and added the source directly which allows me to achieve the visibility I need to see where the lrc calculation is occurring (ModbusUtil.java).

    My next step is to try and figure out why the calculation is not producing the expected result.

     

Log in to post a comment.

MongoDB Logo MongoDB