Modbus one vs. multiple slaves

I have the following configuration working:

openhab.cfg:

modbus:serial.slave1.connection=/dev/ttyUSB0:9600:8:none:1:rtu
modbus:serial.slave1.start=0
modbus:serial.slave1.length=2
modbus:serial.slave1.type=input
modbus:serial.slave1.valuetype=float32

modbus:serial.slave2.connection=/dev/ttyUSB0:9600:8:none:1:rtu
modbus:serial.slave2.start=70
modbus:serial.slave2.length=2
modbus:serial.slave2.type=input
modbus:serial.slave2.valuetype=float32

items:

Number MeterVoltage "Meter voltage [%.1f V]" (All) {modbus="slave1:0"}
Number MeterFreq "Meter frequency [%.1f Hz]" (All) {modbus="slave2:0"}

Is it possible to keep just one slave definition and change the register address in the item definition?

Thanks!

If they were consecutive registers then you could.

What will be the right syntax then?

Try this syntax

openhab.cfg

modbus:tcp.slave5.connection=192.168.0.9
modbus:tcp.slave5.type=holding
modbus:tcp.slave5.start=9
modbus:tcp.slave5.length=4
modbus:tcp.slave5.valuetype=int32

Items
Number MyLongTest1 “Long Test 1 [%x]” (gMB) {modbus=“slave5:0”}
Number MyLongTest2 “Long Test 2 [%x]” (gMB) {modbus=“slave5:1”}

In openhab.cfg it defines the data type (int32) and number of modbus registers, as 4 to give 8 bytes which holds 2 int32 values

Then the Items offset is the int32 in the array 0 is the first and 1 is the second

tom

Thanks for that, Tom.
It does work as you described but does not help in my situation. My meter reports data in registers 0, 6, 12, 24. It seems there is a limit on length, so I’m getting ‘ModbusSlave error getting responce from slave’ if I’m using length higher than 4. I thought I can read for example 8 registers (0 to 7) and then use only indexes 0 and 3.

Yes 8 registers would be 4 32bit variables.

So what is the harm in having more than one slave definition?

There will still be the same number of modbus transactions

am I missing the downside?

Tom

For some reasons it works now :slight_smile:
Just configured once again: length=8, then {modbus=“slave1:0”} and {modbus=“slave1:3”}.
Thanks again, Tom!