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?
You cannot write an input.
Sent from my Moto G (5S) Plus using Tapatalk
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?
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)
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.
You should be able to write the input using pointer as follows:
myWord: POINTER TO WORD;
myWord^:=777; //Write the Full input Word
myWord^.0:=FALSE; //Write bit 0 in input Word
You should also add modbus master device on your device. The ip address - the ip of your plc. Create the channel (Write holding register) with a "Rising edge" option and offset to your register which you want to reset. When u received smth, just active this trigger.
Log in to post a comment.