Hi
I came across with a curious situation when using jamod to write to modbus. Following read code works perfectly:
public static void main(String[] args) throws Exception {
InetAddress address = InetAddress.getByName("host.somewhere");
TCPMasterConnection connection = new TCPMasterConnection(address);
connection.setPort(502);
connection.connect();
ReadMultipleRegistersRequest request = new ReadMultipleRegistersRequest(0, 1);
ReadMultipleRegistersResponse response = (ReadMultipleRegistersResponse)
executeTransaction(connection, request);
}
private static ModbusResponse executeTransaction(TCPMasterConnection connection,
ModbusRequest request)
throws ModbusIOException, ModbusSlaveException, ModbusException {
ModbusTCPTransaction transaction = new ModbusTCPTransaction(connection);
transaction.setRequest(request);
transaction.execute();
return transaction.getResponse();
}
But trying to write similar manner fails (Jamod tries 3 times, each times encounters SocketTimeoutException and finally throws ModbusException).
public static void main(String[] args) throws Exception {
final InetAddress address = InetAddress.getByName("host.somewhere");
final TCPMasterConnection connection = new TCPMasterConnection(address);
connection.setPort(502);
connection.connect();
Register reg = new SimpleRegister(0);
WriteMultipleRegistersRequest request = new WriteMultipleRegistersRequest(0,
new Register[]{reg});
executeTransaction(connection, request);
}
Yes, I know that I am using multi-register versions of the request-objects, but device I'm working with only supports function codes 3 and 16.
I also wrote raw-socket tester to write registers, and as far as I can see it works correctly. But it would be nice to use jamod in both situations.
Does anyone have anyone experience using jamod and would that one be kind enough to tell what I'm doing wrong? This happens with both 1.1 and 1.2rc1 versions of jamod. Or is this possibly some vendor-specific situation?