Inputs and Outputs via Modbus with Wago 750-352 / Openhab 2

Hi!

I’ve got a Wago Modbus coupler with one module with 4 INs and one with 4 OUTs.

When I connect to the coupler using a selfmade LabVIEW program, everything works as expected:

  • FC2 with start 0 & length 4 bits reads the 4 INs
  • FC5 with address 0…4 sets one of the 4 OUTs
  • FC2 or FC1 with start 512 & length 4 bits reads the state of the 4 OUTs (according to the manual, offset 0x200)

With Openhab I can read inputs and write outputs, this already works. But I dont know how to read back the state of the outputs correctly. I don’t understand the principle:

modbus.cfg tells the modbus binding, where to read (“query”) input bits. So I could read discretes with start=0/length=4 and read the state of my coils with start=512/length=4, but the coils have to be written beginning from 0.

For example in modbus.cfg:

tcp.slave1.connection=xxx.xxx.xxx.xxx:502
tcp.slave1.type=discrete
tcp.slave1.start=0
tcp.slave1.length=4

tcp.slave2.connection=xxx.xxx.xxx.xxx:502
tcp.slave2.type=coil
tcp.slave2.start=512
tcp.slave2.length=4

I know about the

modbus="slave2:<x:>y" 

syntax, but how do I tell, that the binding should write to 0 and read from 512? slave2:<512:>0 does not work. And configuring start=0 and length=515 does not work because there’s nothing between 4 and 511 and these values are invalid…
And how do I explicitely force a FC5 call to write the coils at 0…3

What would be the correct way?

Writing coils is always done using FC5

Add another slave

tcp.slave1.connection=xxx.xxx.xxx.xxx:502
tcp.slave1.type=discrete
...

tcp.slave2out.connection=xxx.xxx.xxx.xxx:502
tcp.slave2.type=coil
tcp.slave2.start=0
tcp.slave2.length=4

tcp.slave2in.connection=xxx.xxx.xxx.xxx:502
tcp.slave2.type=coil
tcp.slave2.start=512
tcp.slave2.length=4

Then you can configure coil tems

Switch mycoil "my coil" <someicon> {modbus="<[slave2in:0],>[slave2out:0]"}

You will need to install the latest binding if you are using OH2 stable

I tried modbus.cfg

tcp.slave1.connection=xxx.xxx.xxx.xxx:502
tcp.slave1.type=discrete
tcp.slave1.length=4

tcp.slave2in.connection=xxx.xxx.xxx.xxx:502
tcp.slave2in.type=coil
tcp.slave2in.start=512
tcp.slave2in.length=4

tcp.slave2out.connection=xxx.xxx.xxx.xxx:502
tcp.slave2out.type=coil
tcp.slave2out.start=1
tcp.slave2out.length=4

and item

Switch Sw3 "Sw3" (ALL) {modbus="<[slave2in:0],>[slave2out:0]"}
Switch Sw4 "Sw4" (ALL) {modbus="<[slave2in:1],>[slave2out:1]"}

but this didn’t even switch the outputs any more.

I finally succeeded with

Switch Sw3 "Sw3" (ALL) {modbus="slave2in:0"}
Switch Sw4 "Sw4" (ALL) {modbus="slave2in:1"}

but unfortunately this implies only being able to write outputs starting from 0.
I’m using a OpenhabianPI installed a week ago with “binding-modbus1 - 1.9.0”, this version should be the latest one…

Don’t assume, FIND OUT what binding version you have. I doubt you have the experimental 1.10 version that is needed for this. Re-read the post linked to.

Why does your slave2out config start at 1? You wanted 0 earlier on.

You’re right, that’s a mistake: 0 instead of 1.

As I stated, I use 1.9.0. Saw your link and will try it…

1.10.0 seems to work as expected although it took me a little time to get it installed. Thank you for the advice!!