Modbus data writing issue

Hello B&R family,

I am currently experiencing an issue with establishing Modbus communication on a B&R X20CP1685 PLC. I have integrated the ModbusTCP_any function block into the project and configured it according to the reference image attached. However, I am unable to read or transmit data successfully.

Despite assigning a signal or integer value to the DataWrite variable, the PLC does not appear to send or receive data as expected. I would appreciate your assistance in identifying the root cause of this issue and any guidance you can provide to resolve it.

Thank you in advance for your support.

Best regards,
Anil

Hi,

it’s really hard to say without knowing more about the network setup, the use-case you want to achive, the PLCs fieldbus logger and so on.

The first question is: should the PLC be a ModbusTCP master or slave?
Because using a ModbusTcp_any device in the hardware tree implies that the PLC should act as a master (the xxx_any devices are always the slaves where the master should communicate with), but your PLCs setup is declaring the PLC as a ModbusTCP slave (which is normally used if the PLC should deliver data to a ModbusTCP master somewhere in the network) but without any channel configuration?

Best regards!

Hi Alexander;

I want to use PLC as a slave and send the counter module data to my PC. I can connect to the PLC with IP address shown in photos and i can control and monitor the PLC.
Yes i am trying to deliver data. Yet If i make channel configuration on ethernet section, i can only read but cant write any data.

Best regards,
ANIL

Hi,

okay, if you want the PLC as modbus slave, a ModbusTcp_any device is not neccessary.

The channel configuration (independent if you use the dynamic or static channel configuration) is neccessary, to provide the “link” via IO mapping between your process variables and the modbus data.

ModbusTCP uses 4 different type of data:
coils, discrete inputs (both “1-bit values”, → booleans) , holding registers and input registers (both “16-bit values” → integers).
One of the bool registers and of the interger registers is read-only, the other one is read-write.

Here for example described for the bool registers (from Google AI):
In Modbus TCP, coils are discrete, readable and writable, single-bit outputs, while discrete inputs are read-only, single-bit inputs. Both represent binary states (ON/OFF, True/False) but differ in their write capabilities. Coils are used for controlling outputs like relays, whereas discrete inputs represent sensor readings or switch states.

As you described you’re able to read but not to write: maybe you’ve accidently used the wrong channel type?
And one more hint: please be aware of your cyclic code if using read/write channels → for exapmple if you’re cyclic writing a value to a process variable in your task, you’ll overwrite the value maybe received from Modbus master.

Best regards!

Thanks for nice answer. But i want to write integer data to from PLC. Even though configuration says you can write 32 bit integer, PLC doesn’t send any data.

Best regards,
ANIL

Hi,

I’m still not sure if I got the issue / the usecase right.

ModbusTCP itself only knows 2 types: discretes and registers, so if you want to send / receive a int32 value via modbus, this has to be done via 2 related registers.
The’re several possibilities to do this, e.g. by suitable channel configuration, or by splitting the value manually into two 16-bit values when sending (“high” and “low” register) and join them after receiving, by using memcpy over multiple registers → it also depends on the communication partner and it’s (re-)interpretation of the 16-Bit registers, what’s the best way to implement it.

The’re several posts in the Community about Modbus(TCP) data transfer of “non-16 bit” values, for example the following ones.
Even some of them aren’t about ModbusTCP but Modbus RTU and are not covering exactly the int32 value (but other types > 16bit), the context behind is similar.
So maybe they could help answering your question.

Best regards!