Hello everyone
I am having some confusion regarding the adresses used in the modbus binding. I am trying to read two holding registers from a modbus device over TCP. In the binding documentation it says:
Input as zero-based index number, e.g. in place of
400001
(first holding register), use the address"0"
I am quite sure there is a zero too much and it should be 40001
(or not?), but that’s not the problem. The first holding register I am trying to read is 41018 (with zero based addressing probably 41017) with a length of two, so my things file looked like this:
Bridge modbus:tcp:smartfoxtcp [ host="192.168.178.81", port=502, id=1 ] {
// read-write for holding registers. Reading 4 registers, with index 1017, 1041
// These correspond to holding register numbers 41017, 41041
Bridge poller holding1 [ start=1017, length=2, refresh=120000, type="holding" ] {
Thing data holdingPowerTotal [ readStart="1017", readValueType="int32" ]
}
Bridge poller holding2 [ start=1041, length=2, refresh=120000, type="holding" ] {
Thing data holdingPowerAnalogout [ readStart="1041", readValueType="uint32" ]
}
}
However, that generates the following error:
2021-12-23 21:44:30.255 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing ‘modbus:poller:smartfoxtcp:holding2’ changed from ONLINE to OFFLINE (COMMUNICATION_ERROR): Error with read: org.openhab.core.io.transport.modbus.internal.ModbusSlaveErrorResponseExceptionImpl: Slave responsed with error=2
I read in a thread in this forum that this means, that I have a connection but the device tells me I can’t run this operation on this address. So I started playing around with the adresses in the modbus.things file in a way which is totally not according to the documentation by writing the full adresses and not only the offset to 40000:
Bridge modbus:tcp:smartfoxtcp [ host="192.168.178.81", port=502, id=1 ] {
// read-write for holding registers. Reading 4 registers, with index 1017, 1041
// These correspond to holding register numbers 41017, 41041
Bridge poller holding1 [ start=41017, length=2, refresh=120000, type="holding" ] {
Thing data holdingPowerTotal [ readStart="41017", readValueType="int32" ]
}
Bridge poller holding2 [ start=41041, length=2, refresh=120000, type="holding" ] {
Thing data holdingPowerAnalogout [ readStart="41041", readValueType="uint32" ]
}
}
Now everything works and I get the correct values in my items, at least for positive values (negative have not yet occured). But I am unsure if this is only by change and it will stop working in some cases.
Is this just a problem of the documentation or am I missing something? It’s my first modbus project so maybe I just don’t know about this protocol…
I am running openhab 3.1.0 release build with the corresponding binding. The modbus device is a “Smartfox Pro”. If any information is missing I will of course add it to this thread.
Thank you very much in advance for everybody who will try to help me understand this.
regards, Ueli