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
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: