I am working on a project where we are producing specialized hardware controlled by a java application through the modbus protocol.
For automated testing purposes (only software without the actual hardware) we would like to instantiate a properly configured slave instance from the test code. I can see that I have to use the ModbuspalPane class, but it is unclear how to go from there to set up coils and registers when I have created a ModbusPal.slave instance.
Best regards
Jørgen
Last edit: Jørgen Bundgaard Wanscher 2014-08-14
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Seems like I figured most of it out by skimming the source code - hurray for OSS :-)
Instantiate a slave (ModbusPal.slave.ModbusSlave)
slave = new ModbusSlave(0);
Setup Coils and Holding registers through getCoils and getHoldingRegisters methods on the slave instance.
slave.getCoils().create(....)
slave.getHoldingRegisters.create(....)
Create a project (ModbusPalProject)
ModbusPalProject project = new ModbusPalProject();
Use the submitModbusSlave method on the project instance to attach the configured slave
project.submitModbusSlave(slave);
Make the pane instance and use the newly created project
modbuspal = ModbusPalGui.getInstance(instanceKey);
modbuspal.setProject(project);
Now use the start and stop commands on the pane to control operation of the slave
Open issues:
a) How do I programmatically change the port number of the slave/project
b) How do I programmatically change the name of the project
- note that both open issues could be solved by saving to XML and then modifying the XML and reloading, or by modifying the modbuspal source code but I hope there is an easier way to achieve a) and b) :-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am working on a project where we are producing specialized hardware controlled by a java application through the modbus protocol.
For automated testing purposes (only software without the actual hardware) we would like to instantiate a properly configured slave instance from the test code. I can see that I have to use the ModbuspalPane class, but it is unclear how to go from there to set up coils and registers when I have created a ModbusPal.slave instance.
Best regards
Jørgen
Last edit: Jørgen Bundgaard Wanscher 2014-08-14
Seems like I figured most of it out by skimming the source code - hurray for OSS :-)
slave = new ModbusSlave(0);
slave.getCoils().create(....)
slave.getHoldingRegisters.create(....)
ModbusPalProject project = new ModbusPalProject();
project.submitModbusSlave(slave);
modbuspal = ModbusPalGui.getInstance(instanceKey);
modbuspal.setProject(project);
Open issues:
a) How do I programmatically change the port number of the slave/project
b) How do I programmatically change the name of the project
- note that both open issues could be solved by saving to XML and then modifying the XML and reloading, or by modifying the modbuspal source code but I hope there is an easier way to achieve a) and b) :-)