I am currently writing a Modbus TCP/IP Slave using the J2Mod V 3.0. I have created the slave and have it listening on the correct port and can connect to it from my PC (using Simply Modbus). What I cannot seem to figure out is how do I monitor the connections that my Slave is receiving? How do I know when a Master writes to one of my registers? Any help is appreciated. I am including how I setup the slave just in case that helps.
void createSlave() {
try {
String ip = Model.getInstance().plcSettings().getIPAddress(true);
String[] ipStringArray = ip.split("\\.");
byte[] addr = new byte[4];
for (int i = 0; i < ipStringArray.length; i++) {
addr[i] = Byte.parseByte(ipStringArray[i]);
}
slave = ModbusSlaveFactory.createTCPSlave(InetAddress.getByAddress(addr), port, 5, false, (Model.getInstance().plcSettings().getIdleTimeout() * 60));
slave.addProcessImage(1, image);
slave.open();
} catch (NumberFormatException | ModbusException | UnknownHostException modException) {
modException.printStackTrace();
}
}
I have actually reached out and was responded to by Steve O'Hara. It turns out with J2mod there is currently no way to monitor a connection. Shout out to him for responding and being so cool about everything.