CODESYS - the IEC 61131-3 automation software

MODBUS Holding Registers Read/Write issue
Page 1 of 1

Author:  mikeardy [ Fri Nov 30, 2018 8:10 am ]
Post subject:  MODBUS Holding Registers Read/Write issue

I have defined a Slave Device in ModbusTCP, as in picture 1 attached.
I defined the registers as picture 2 attached.
When the partner writes to an holding register I receive correctly the value, but I need to overwrite is after a while.
Codesys does not permit to me to do this, picture 3.
How can I overwrite the register?
Thank you

Author:  Josep M. Rams [ Sat Dec 01, 2018 8:17 pm ]
Post subject:  Re: MODBUS Holding Registers Read/Write issue


You cannot write an input.

Sent from my Moto G (5S) Plus using Tapatalk

Author:  mikeardy [ Mon Dec 03, 2018 2:24 am ]
Post subject:  Re: MODBUS Holding Registers Read/Write issue

yes but they are Holding Registers and according to Modbus specification holding register can be read and written at the same way. May I use a library to achieve it?

Author:  dFx [ Mon Dec 03, 2018 3:51 pm ]
Post subject:  Re: MODBUS Holding Registers Read/Write issue

Modbus is a one way communication, It only allows one master to read/write into a slave. That said, if, Inside your slave, you need to update writeable values then you have several workarounds :

1) Don't always write with master, if you can edit it. Just write when you have to transmit a value change. You must read back the value with the master to update it on the master. Otherwise your master with have a different value than your slave.

2) You have no way to not write cyclically, then you may read before write. Meaning, first master reads, then update internally the write value. Then master will perform writes on your slave. This has one drawback : in case of writing your value just after the read and before the write, it will be overwrited by master's value. Operator/program may have to write more than once the value to correctly update it. This works best with low cycle time (modbus wise).

For exemple :
We have a setpoint on the slave. The slave may limit it -> this would be continuous value update (slave side) and will work flawlessly (protecting the setpoint before using it)

Author:  RoryLDM [ Thu Jan 10, 2019 5:28 pm ]
Post subject:  Re: MODBUS Holding Registers Read/Write issue

What you have to do is take that modbus input and translate it to another variable that you can change. The simplest way to do this is with the function block SEL. What you have to do is consider when you want the modbus value to overwrite the local value.

Below is a very quick example, and there are better ways to do it especially with structured text. You would need to think of the control logic for both the trigger options. I might use a comparison of the stored modbus value with the input value and if it's not the same it stores the new value and resets the local override.


Author:  jzhvymetal [ Fri Jan 11, 2019 5:09 pm ]
Post subject:  Re: MODBUS Holding Registers Read/Write issue

You should be able to write the input using pointer as follows:


myWord^:=777;        //Write the Full input Word
myWord^.0:=FALSE;   //Write bit 0 in input Word

Page 1 of 1 All times are UTC+01:00
Powered by phpBB® Forum Software © phpBB Limited