Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

IoDrvModbusTCP - Programmatically change Unit ID

Scoobler
2022-09-23
2022-09-26
  • Scoobler - 2022-09-23

    Hello,

    I have a project with a package controller fitted to a machine - it has a feature where the overall package parameters are available via Unit ID 100 - this is static. The machine specific details are then available via a different Unit ID.
    When several machines are plugged into each other, these IDs will increment - so the package controller (an IPC) will respond for the entire package via Unit ID 100, but if I want to check details for machine 1, it will be Unit ID 1, for machine 2 it would be Unit ID 2 etc.

    The PLC I am putting together will allow control over the package, there is also a HMI - I want the user to be able to change the ID number so they can view individual machines as well - without having to add lots of individual IoDrvModbusTCP devices with the Unit ID set on each one.

    I have looked at the library but can't see a way to change the Unit ID programmatically - so thought I would check and see if I am missing something and there is another way possibly?

     
  • i-campbell

    i-campbell - 2022-09-23

    so if you have your device tree lain out like the red circle with the three in it here: https://content.helpme-codesys.com/en/CODESYS%20Modbus/_mod_general.html

    Then you could access it like:
    change it with RTU_Slave1.SlaveAddress:=2;

    Not sure if you need to set RTU_Slave1.Enable to false first or not to be allowed to change it.

     
    πŸ‘
    1
  • Scoobler - 2022-09-23

    Thanks for the suggestion, unfortunately it is Modbus TCP, the SlaveAddress is for Modbus RTU and isn't present on the communication settings for Modbus TCP.

    Setting the Unit ID is available via the GUI, but I can't seem to find it to change other than at compile time.

     

    Last edit: Scoobler 2022-09-23
  • i-campbell

    i-campbell - 2022-09-24

    The solution I suugested was for tcp. Take a look at the red circled 3 in the link.
    If it has more than one unit ID, the TCP slave is acting as a gateway, and you add the unit IDs as serial com devices beneath the tcp slave. A bit counterintuitive for sure.

     
  • Scoobler - 2022-09-26

    Hi i-campbell, I tried adding the 'slave COM port' under the TCP Slave - however there was no SlaveAddress - the only thing was an output showing the usiUnitID - however there didn't appear to be a way to set this in the code.

     

Log in to post a comment.