Modbus TCP - Beckhoff cx9000: contact item issues

I want to setup a communication between Openhab and a Beckhoff cx9000.
The prefered protocol is Modbus TCP.

It’s not clear for me what device is the server and which is the client?
Do I setup the Beckhoff as a client or as a server?

If I had to guess I would say setup the Beckhoff as a client. Modbus works usually with OpenHAB being the Master and the devices it has to read as slaves. To my knowledge no one has written a Modbus/TCP Slave binding for OpenHAB.

Terminology can get a bit confusing with Modbus/TCP.
In Modbus, a master polls - it initiates communication with slave(s) to provoke a response.
In TCP, a client initiates comms to server(s).
So counter-intuitively, Modbus master = TCP client. As Openhab fills the master/client role, I think you need to configure the Beckhoff as a TCP server, if that is possible.

So far, the test setup works!
there is communication with openhab and a PC running Modbus Slave from modbustools.com
I can set and reset coils on the slave simulator.
next, setting up the cx

Ok, i’ve created a very basic PLC program:

PROGRAM MAIN
VAR
Q00 AT%QX0.0 : BOOL;
Q01 AT%QX0.1 : BOOL;
Q02 AT%QX0.2 : BOOL;
Q03 AT%QX0.3 : BOOL;
Q04 AT%QX0.4 : BOOL;
Q05 AT%QX0.5 : BOOL;
Q06 AT%QX0.6 : BOOL;
Q07 AT%QX0.7 : BOOL;
END_VAR

Also, installed the Modbus TCP server on the device and linked the above variables to the physical digital outputs

With this, I can read and control the outputs of the cx controller.

Next step, reading of the input status.

Ran into my first problem: it seems that the contact item is not working with the modbus input type.
It will work of I link it to a modbus coil.
The modbus input type can I link with a switch item.

This is the modbus binding configuration:
modbus:tcp.slave1.connection=192.168.1.110:502
modbus:tcp.slave1.id=1
modbus:tcp.slave1.type=coil
modbus:tcp.slave1.start=0
modbus:tcp.slave1.length=8

modbus:tcp.slave2.connection=192.168.1.110:502
modbus:tcp.slave2.id=1
modbus:tcp.slave2.type=input
modbus:tcp.slave2.start=0
modbus:tcp.slave2.length=8

And this is how the CX controller is configured:
PROGRAM MAIN
VAR
Q00 AT%QX0.0 : BOOL;
Q01 AT%QX0.1 : BOOL;
Q02 AT%QX0.2 : BOOL;
Q03 AT%QX0.3 : BOOL;
Q04 AT%QX0.4 : BOOL;
Q05 AT%QX0.5 : BOOL;
Q06 AT%QX0.6 : BOOL;
Q07 AT%QX0.7 : BOOL;

I00 AT%IX0.0 : BOOL;
I01 AT%IX0.1 : BOOL;
I02 AT%IX0.2 : BOOL;
I03 AT%IX0.3 : BOOL;
I04 AT%IX0.4 : BOOL;
I05 AT%IX0.5 : BOOL;
I06 AT%IX0.6 : BOOL;
I07 AT%IX0.7 : BOOL;

END_VAR

1 Like

Isn’t the modbus binding type ‘input’ intended to read a register i.e. a numeric value, like an ADC input? I thought type ‘discrete’ is a better match for on/off contact style inputs.

That is it, figured it out myself also.
Next, find a solution to control my universal push button dimmers. Does it
exist, Modbus dimmers?

I have the same requirement. Can you post me the complete code of the XC.
Thanks a lot.

best regards
Timo