I am trying to make a Modbus Slave and Master using j2mod
(it's version 1.0.6 tho, so that is compatible with another program).
And I do have some general questions about the code I found online.
I have found almost no useful documentation what so ever, so I'm kind of clueless.
TcpMaster
this.addr = InetAddress.getByName("127.0.0.1");
conn = new TCPMasterConnection(addr);
conn.setPort(port);
conn.connect();
req = new ReadInputDiscretesRequest(ref, count);
trans = new ModbusTCPTransaction(conn);
trans.setRequest(req);
trans.execute();
res = (ReadInputDiscretesResponse) trans.getResponse();
TcpSlave
spi = new SimpleProcessImage();
spi.addDigitalOut(bitOut);
ModbusCoupler.getReference().setProcessImage(spi);
ModbusCoupler.getReference().setMaster(false);
ModbusCoupler.getReference().setUnitID(1);
addr = InetAddress.getByName("127.0.0.1");
listener = new ModbusTCPListener(3);
listener.setPort(port);
listener.setAddress(addr);
listener.setUnit(1);
listener.setListening(true);
listener.run();
So right now I'm getting an Illegal Data Address error at trans.execute()
and my questions are:
What exactly are the two parameters on the Request
req = new ReadInputDiscretesRequest(ref, count);
Where do I define the UnitId
the Master has to access (in the Master class).