MODBUS Holding Registers Read/Write issue

mikeardy
2018-11-30
2020-04-14
  • mikeardy - 2018-11-30

    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

    IMG: picture 3.JPG

    IMG: picture 2.JPG

    IMG: picture 1.JPG

     
  • josepmariarams - 2018-12-01

    Hi

    You cannot write an input.

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

     
  • mikeardy - 2018-12-03

    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?

     
  • dFx

    dFx - 2018-12-03

    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)

     
  • RoryLDM - 2019-01-10

    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.

    IMG: Bild

     
  • jzhvymetal - 2019-01-11

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

    PROGRAM POU
    VAR
    Β  Β myWord: POINTER TO WORD;
    END_VAR
    myWord:=ADR(iwModbusTCP_Slave_Device_Inputs_0);
    myWord^:=777;Β  Β  Β Β  Β //Write the Full input Word
    myWord^.0:=FALSE;Β  Β //Write bit 0 in input Word
    
     
  • dpua - 2020-04-14

    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.