How to set unitId when i use modbus-tcp-slave #117
Replies: 1 comment 3 replies
-
|
The unit id isn't selected by the transport. Your implementation of Optionally, you can use protected abstract Optional<ProcessImage> getProcessImage(int unitId);For example, this would use the same ProcessImage for any unit id provided by the client: var processImage = new ProcessImage();
var modbusServices =
new ReadWriteModbusServices() {
@Override
protected Optional<ProcessImage> getProcessImage(int unitId) {
return Optional.of(processImage);
}
};and this would support only unit id 1 and 2, the rest being unsupported: var processImage = new ProcessImage();
var modbusServices =
new ReadWriteModbusServices() {
@Override
protected Optional<ProcessImage> getProcessImage(int unitId) {
return switch (unitId) {
case 1, 2 -> Optional.of(processImage);
default -> Optional.empty();
};
}
};Which approach is more appropriate depends what you are trying to build. The ProcessImage approach is good if your data is in memory. If you're trying to implement e.g. a gateway, then you probably need to just implement |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
var serverTransport = NettyTcpServerTransport.create(cfg -> {
cfg.bindAddress = "localhost";
cfg.port = 50200;
});
Beta Was this translation helpful? Give feedback.
All reactions