Modbus RTU Drexel & Weiss <> openHAB

I’m not doing it for you, but will offer help.

You should already have your guide, but there is a lot in it

You can see more sample Modbus slave definitions, like you want to use in modbus.cfg, here

You should have everything you need to set up your first Modbus slave, apart from this part

Modbus numbers always come in 16-bit registers (words) over the protocol , but there are different ways to interpret 16-bit registers and/or combine them into e.g. 32-bit registers.

Looking at page 13/16 it suggests that reading one data value from the D&W is returned as 4 bytes, that is two 16-bit Modbus words, together representing a 32-bit signed integer.
I think the datatype your modbus slave requires will be 32 bit signed int. With that knowledge, you might find more mention of that fact in the manual.

Bearing in mind 32 bits is two Modbus words, you need to double the config length parameter - for your starter case to read one temperature, use length 2

Have a try, and show us what your modbus.cfg looks like

I don’t know how many times i tried to understand the off. Modbus binding page.
i don’t get that at all. as i previously mentioned Modbus is completely new.
Reading the Modbus binding page confuses me more and more.

type:

[quote]type=coil uses function 1 “Read Coil Status”
type=discrete uses function 2 “Read Input Status” (readonly inputs)
type=holding uses function 3, “Read Holding Registers”
type=input uses function 4 “Read Input Register” (readonly-registers eG analogue inputs)[/quote]

[quote]In the traditional standard, [entity] numbers for those entities start with a digit, followed by a number of four digits in range 1–9,999:
coils numbers start with a zero and then span from 00001 to 09999
discrete input numbers start with a one and then span from 10001 to 19999
input register numbers start with a three and then span from 30001 to 39999
holding register numbers start with a four and then span from 40001 to 49999

This translates into entity addresses between 0 and 9,998 in data frames.

The openhab modbus binding uses data frame entity addresses when referring to modbus entities. That is, the entity address configured in modbus binding is passed to modbus protocol frame as-is. For example, modbus slave definition with start=3, length=2 and type=holding will read modbus entities with the following numbers 40004 and 40005.[/quote]
i (think…) i understand why the modbus slave definition reads modbus entities 40004 and 40005, but i absolutely don’t geht where these numbers point to?
Let’s stay with the example on page 10 of my first pdf…

Anfrage = request / Anwort = response / last row: it’s possible / mandatory to read 2 registers (?!)

should i be able to geht all the informations needed from this? should i look at the request or response seciton? HEX/DEC row?

with all that new knowledge (with extends to… not a lot) my modbus.cfg. extends to this:

serial.slave1.connection/dev/tty1:9600:8:none:1:rtu serial.slave1.length=2

i’m really not looking for anyone to set up my heating device, but as you can see i’m struggling pretty bad…
so i’d be really thankful if you had the patience to push me in the right direction…

am i even looking in the right direction (modbus entities) oder is that the wrong approach?

Greetings, very confused greetings.

The example in your PDF says the heating device is read usin function 04, also known as FC4 in modbus-speak.
Looking at the OpenHAB binding guide,

you will find only one choice for function 4.

Now you can add another line to your config. (type)

Your device’s manual does not refer to such large value addresses, you simply need not worry about it. There is a Modbus convention around 5-figure decimal addresses, but you don’t have any.

Now you can add another line to your config. (start)

Your device’s manual is showing you exactly what Modbus transactions look like. In this case, OpenHAB plays master and generates a request, the heating plays slave and generates a response,
The binding takes care of this structure, and the CRC checksum and so on, but the example is useful for extracting the details that you need to configure the binding

Already had the explanation about the “basic unit” of Modbus being a register as a 16-bit word, that is two bytes. Modbus words can be lumped together to form 32-bit words. A slave device presenting some data in the form of a 32-bit value might well say in its manual to read two registers … make sense?
This why we have length 2 in the config.

Of course OpenHAB needs to be told how the data is presented, it cannot guess.

Now you can add another line to your config (datatype)

[quote=“rossko57, post:23, topic:22379”]
you will find only one choice for function 4.
Now you can add another line to your config. (type)[/quote]
Where did you get that in the pdf?

“read input registers: FC 4 (Read Input Registers)”
(so writing would be: "write holding register: FC 6 (Write Single Holding Register), OR FC 16 (Write Multiple Holding Registers) (see note on writemultipleregisters configuration parameter below) > type=holding

serial.slave1.connection/dev/tty1:9600:8:none:1:rtu serial.slave1.type=input serial.slave1.length=2

i’m guessing here…

serial.slave1.start=202but it’s probably not just the register number?

[quote=“rossko57, post:23, topic:22379”]
Now you can add another line to your config (datatype)
[/quote][quote=“rossko57, post:23, topic:22379”]
A slave device presenting some data in the form of a 32-bit value might well say in its manual to read two registers[/quote]

well, i can try?

serial.slave1valuetype=int32

Just because you stated it in your post - i’m not sure why…

Yep, it is usually that simple. It can get more complicated, but try simple first.

Because your D&W manual says to read two Modbus registers, that’s 2 x 16-bits, and it says the temperature is signed. So, signed 32-bit integer.
Again it can get more complicated (which of the 16-bit chunks is the high half) but lets start simple.

If you have twinkly lights on your serial interface, they should be twinkling by now. And if you look in your log, the binding may be giving you messages.

Next, to set up a Number Item to receive the data from this defiined slave.

modbus.cfg:

serial.slave1.connection/dev/tty1:9600:8:none:1:rtu serial.slave1.id=2 serial.slave1.type=input serial.slave1.length=2 serial.slave1.start=202 serial.slave1.valuetype=int32

id = 2 because heating has id 2 in the heaters system (while id 1 is air circulation module) ?

item.

“0” means start+0 / 202+0 = 202, right?

Yes, 0 means first (and only) of 32-bit chunks defined by slave1

Item type is Number though, these things matter.

I don’t have enough German to confirm what the ID should be.

Things should be happening - logs, twinkly lights, value of Temp1 in your sitemap?

2017-03-29 18:34:05.584 [ERROR] [ing.ModbusSlaveConnectionFactoryImpl] - connect try 1/3 error: Modbus serial device doesn't exist!. Connection SerialConnection@936bf6[portName=,port=<null>]. Endpoint ModbusSerialSlaveEndpoint@e79cf3[portName=] 2017-03-29 18:34:05.585 [ERROR] [ing.ModbusSlaveConnectionFactoryImpl] - connect try 2/3 error: Modbus serial device doesn't exist!. Connection SerialConnection@936bf6[portName=,port=<null>]. Endpoint ModbusSerialSlaveEndpoint@e79cf3[portName=] 2017-03-29 18:34:05.585 [ERROR] [ing.ModbusSlaveConnectionFactoryImpl] - connect try 3/3 error: Modbus serial device doesn't exist!. Connection SerialConnection@936bf6[portName=,port=<null>]. Endpoint ModbusSerialSlaveEndpoint@e79cf3[portName=] 2017-03-29 18:34:05.586 [ERROR] [ing.ModbusSlaveConnectionFactoryImpl] - re-connect reached max tries 3, throwing last error: Modbus serial device doesn't exist!. Connection SerialConnection@936bf6[portName=,port=<null>]. Endpoint ModbusSerialSlaveEndpoint@e79cf3[portName=] 2017-03-29 18:34:05.586 [ERROR] [ing.ModbusSlaveConnectionFactoryImpl] - Error connecting connection SerialConnection@936bf6[portName=,port=<null>] for endpoint ModbusSerialSlaveEndpoint@e79cf3[portName=]: Modbus serial device doesn't exist! 2017-03-29 18:34:05.587 [WARN ] [.binding.modbus.internal.ModbusSlave] - ModbusSlave (slave1): Error getting a new connection for endpoint ModbusSerialSlaveEndpoint@e79cf3[portName=]. Error was: Unable to validate object 2017-03-29 18:34:05.588 [WARN ] [.binding.modbus.internal.ModbusSlave] - ModbusSlave (slave1) not connected -- aborting read request net.wimpi.modbus.msg.ReadInputRegistersRequest@9942ae. Endpoint ModbusSerialSlaveEndpoint@e79cf3[portName=]
can’t connect to slave…

pi is losing connection (wired) very often. there’s something very very wrong here… probably there’s a problem with my serial device…

I think you are missing equals sign in the connection line. Instead of

serial.slave1.connection/dev/tty1:9600:8:none:1:rtu

You should have

serial.slave1.connection=/dev/tty1:9600:8:none:1:rtu

Best
Sami

1 Like

You mean ethernet?
How is the Pi powered - you have added a new device load (serial port).
Where is the Pi located, not in amongst electrical noisy heating switching cabling.
Is it better if you disconnect the serial cable to the heating - there may be some earth loop via the ground wire.

removing modbus.cfg was all i did to get the pi working as usual
i really missed the equal signs :blush:
now there are different errors and warnings…

2017-03-29 20:50:39.949 [WARN ] [.binding.modbus.internal.ModbusSlave] - ModbusSlave (slave1): Error getting a new connection for endpoint ModbusSerialSlaveEndpoint@11b2f2e[portName=/dev/tty1]. Error was: Unable to validate object 2017-03-29 20:50:39.950 [WARN ] [.binding.modbus.internal.ModbusSlave] - ModbusSlave (slave1) not connected -- aborting read request net.wimpi.modbus.msg.ReadInputRegistersRequest@9dd0ca. Endpoint ModbusSerialSlaveEndpoint@11b2f2e[portName=/dev/tty1] 2017-03-29 20:50:40.152 [ERROR] [et.wimpi.modbus.net.SerialConnection] - Could not get port identifier, maybe insufficient permissions. null 2017-03-29 20:50:40.154 [ERROR] [ing.ModbusSlaveConnectionFactoryImpl] - connect try 1/3 error: Could not get port identifier, maybe insufficient permissions. null. Connection SerialConnection@18aa26d[portName=/dev/tty1,port=<null>]. Endpoint ModbusSerialSlaveEndpoint@11b2f2e[portName=/dev/tty1] 2017-03-29 20:50:40.190 [ERROR] [et.wimpi.modbus.net.SerialConnection] - Could not get port identifier, maybe insufficient permissions. null 2017-03-29 20:50:40.191 [ERROR] [ing.ModbusSlaveConnectionFactoryImpl] - connect try 2/3 error: Could not get port identifier, maybe insufficient permissions. null. Connection SerialConnection@18aa26d[portName=/dev/tty1,port=<null>]. Endpoint ModbusSerialSlaveEndpoint@11b2f2e[portName=/dev/tty1] 2017-03-29 20:50:40.228 [ERROR] [et.wimpi.modbus.net.SerialConnection] - Could not get port identifier, maybe insufficient permissions. null 2017-03-29 20:50:40.229 [ERROR] [ing.ModbusSlaveConnectionFactoryImpl] - connect try 3/3 error: Could not get port identifier, maybe insufficient permissions. null. Connection SerialConnection@18aa26d[portName=/dev/tty1,port=<null>]. Endpoint ModbusSerialSlaveEndpoint@11b2f2e[portName=/dev/tty1] 2017-03-29 20:50:40.230 [ERROR] [ing.ModbusSlaveConnectionFactoryImpl] - re-connect reached max tries 3, throwing last error: Could not get port identifier, maybe insufficient permissions. null. Connection SerialConnection@18aa26d[portName=/dev/tty1,port=<null>]. Endpoint ModbusSerialSlaveEndpoint@11b2f2e[portName=/dev/tty1] 2017-03-29 20:50:40.231 [ERROR] [ing.ModbusSlaveConnectionFactoryImpl] - Error connecting connection SerialConnection@18aa26d[portName=/dev/tty1,port=<null>] for endpoint ModbusSerialSlaveEndpoint@11b2f2e[portName=/dev/tty1]: Could not get port identifier, maybe insufficient permissions. null 2017-03-29 20:50:40.232 [WARN ] [.binding.modbus.internal.ModbusSlave] - ModbusSlave (slave1): Error getting a new connection for endpoint ModbusSerialSlaveEndpoint@11b2f2e[portName=/dev/tty1]. Error was: Unable to validate object 2017-03-29 20:50:40.233 [WARN ] [.binding.modbus.internal.ModbusSlave] - ModbusSlave (slave1) not connected -- aborting read request net.wimpi.modbus.msg.ReadInputRegistersRequest@17bbfef. Endpoint ModbusSerialSlaveEndpoint@11b2f2e[portName=/dev/tty1] 2017-03-29 20:50:40.435 [ERROR] [et.wimpi.modbus.net.SerialConnection] - Could not get port identifier, maybe insufficient permissions. null 2017-03-29 20:50:40.435 [ERROR] [ing.ModbusSlaveConnectionFactoryImpl] - connect try 1/3 error: Could not get port identifier, maybe insufficient permissions. null. Connection SerialConnection@1892005[portName=/dev/tty1,port=<null>]. Endpoint ModbusSerialSlaveEndpoint@11b2f2e[portName=/dev/tty1] 2017-03-29 20:50:40.471 [ERROR] [et.wimpi.modbus.net.SerialConnection] - Could not get port identifier, maybe insufficient permissions. null 2017-03-29 20:50:40.472 [ERROR] [ing.ModbusSlaveConnectionFactoryImpl] - connect try 2/3 error: Could not get port identifier, maybe insufficient permissions. null. Connection SerialConnection@1892005[portName=/dev/tty1,port=<null>]. Endpoint ModbusSerialSlaveEndpoint@11b2f2e[portName=/dev/tty1] 2017-03-29 20:50:40.509 [ERROR] [et.wimpi.modbus.net.SerialConnection] - Could not get port identifier, maybe insufficient permissions. null 2017-03-29 20:50:40.510 [ERROR] [ing.ModbusSlaveConnectionFactoryImpl] - connect try 3/3 error: Could not get port identifier, maybe insufficient permissions. null. Connection SerialConnection@1892005[portName=/dev/tty1,port=<null>]. Endpoint ModbusSerialSlaveEndpoint@11b2f2e[portName=/dev/tty1] 2017-03-29 20:50:40.510 [ERROR] [ing.ModbusSlaveConnectionFactoryImpl] - re-connect reached max tries 3, throwing last error: Could not get port identifier, maybe insufficient permissions. null. Connection SerialConnection@1892005[portName=/dev/tty1,port=<null>]. Endpoint ModbusSerialSlaveEndpoint@11b2f2e[portName=/dev/tty1] 2017-03-29 20:50:40.511 [ERROR] [ing.ModbusSlaveConnectionFactoryImpl] - Error connecting connection SerialConnection@1892005[portName=/dev/tty1,port=<null>] for endpoint ModbusSerialSlaveEndpoint@11b2f2e[portName=/dev/tty1]: Could not get port identifier, maybe insufficient permissions. null 2017-03-29 20:50:40.512 [WARN ] [.binding.modbus.internal.ModbusSlave] - ModbusSlave (slave1): Error getting a new connection for endpoint ModbusSerialSlaveEndpoint@11b2f2e[portName=/dev/tty1]. Error was: Unable to validate object 2017-03-29 20:50:40.512 [WARN ] [.binding.modbus.internal.ModbusSlave] - ModbusSlave (slave1) not connected -- aborting read request net.wimpi.modbus.msg.ReadInputRegistersRequest@1a4a17e. Endpoint ModbusSerialSlaveEndpoint@11b2f2e[portName=/dev/tty1] 2017-03-29 20:50:40.714 [ERROR] [et.wimpi.modbus.net.SerialConnection] - Could not get port identifier, maybe insufficient permissions. null 2017-03-29 20:50:40.714 [ERROR] [ing.ModbusSlaveConnectionFactoryImpl] - connect try 1/3 error: Could not get port identifier, maybe insufficient permissions. null. Connection SerialConnection@195ee2d[portName=/dev/tty1,port=<null>]. Endpoint ModbusSerialSlaveEndpoint@11b2f2e[portName=/dev/tty1]
yay

I’m pretty sure i’m having a problem with the serial device…
this is what i get after a clean jessie install and following http://spellfoundry.com/2016/05/29/configuring-gpio-serial-port-raspbian-jessie-including-pi-3/#Using_the_serial_port_with_other_hardware

pi@raspberrypi:~ $ ls -l /dev lrwxrwxrwx 1 root root 7 Mar 29 18:29 serial0 -> ttyAMA0 lrwxrwxrwx 1 root root 5 Mar 29 18:29 serial1 -> ttyS0

but with my openHABian image there’s no serial …

Might be permissions issue, i have no idea about unix, you need someone else’s help.
There are quite a few threads touching on this here if you search.

OpenHAB2 seems to have an unpleasant habit of caching config, ‘removing’ things does not remove them.

posted my problem in openHABian related threat. i hope to resolve this issue and be back soon!
thank you very much in the meantime!

Mind you, your config asks for tty1 and you don’t have one … ttyS0 ?

1 Like

sadly there’s no tty* :frowning:

i think i got it working =)
(not with my operating installation but with a clean raspian jessie and manual install openHABian)

I’m going to bed now and will investigate these beautiful think later =)

Thank you again, i’ll be back

Result! Hard part done.
That doesn’t look much like a temperature in expected “x100” form (XX.XX as XXX without the decimal) though.
You may need to play with wordswap or register numbers yet.

1 Like

format is exactly like it’s descibred in the parameters section.
Where do i need to play with wordswap (?) or register numbers (?) - modbus.cfg or item(s)?

Yep you are right, temperature is reported x1000 not x100 as I wrongly recalled.
If you are expecting temperature around 15C, it is sorted.

the display showed 14.7 °C so it’s right!
conversion must be done with rules/openhab?