Multiple TCP Modbus Slaves
-
Matthew,
That should work. I think you're right in that you might have some class name confusion as people may view the slave at the device id level instead of the networking ip/port level as the new semantics are.
Not that I think it would be a big performance hit, but with the process images backed by a hashmap keyed by slave id, you don't have to do a linear search to find the requested process image.
I may keep my current implementation simply because my process image registry is a collection of process images keyed first by slave id and secondly by my concept of a slave configuration (allowing for more than one process image if a "spill over" process image is needed). This class is thread safe and handles the addition/removal of process images by my slave objects. That said, I think this logic could easily be moved into the ModbusSlave class where if necessary I can create my own implementation.
So the answer to your question is yes with the reservation on the class naming as you pointed out.
Regards,
Fred
-
Good points. The class is now called ModbusSlaveSet and has this relevant code:
protected LinkedHashMap<Integer, ProcessImage> processImages = new LinkedHashMap<Integer, ProcessImage>(); public void addProcessImage(ProcessImage processImage) { processImages.put(processImage.getSlaveId(), processImage); } public ProcessImage getProcessImage(int slaveId) { return processImages.get(slaveId); } public Collection<ProcessImage> getProcessImages() { return processImages.values(); } ...
I used a LinkedHashMap in order to preserve the order in which the process images were added in case the querying order is important to the user.
-
hi, just picked up on this thread.... is this some sort of data source that gives mango the ability to listen on port xxx and accept modbus requests? thus making it a TCP slave? think i needs this :)
Neil
-
This forum is for discussions around the Modbus4J product, which is used in Mango, but otherwise no associated. It is possible to get Mango to act as a modbus slave, but not trivial. If you need this, please use the contact page to request a quote.