Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Info

The Modbus slave from the FAQ Modbus Communikation Master/Slave via Ethernet is used here.


  • Create a "Standard project" and select CODESYS Control Win V3 as the device.
  • Define the target system by means of the Netzwork scan.

    Image Added

  • Insert an Ethernet adapter in the device tree and specify the interface to be used.

    Note

    If a target system is not defined yet, then the error message "Gateway not configured" is displayed.


    Image Added


  • Insert a Modbus TCP Master below the Ethernet adapter in the device tree.
  • Insert a Modbus TCP Slave below the Modbus TCP Master in the device tree.

    Image Added

    Info

    Pay attention that the address is the the same as for the Modbus Slave Device.



  • Adapt the POU PLC_PRG as follows:



    Section
    Column
    width7

    Declaration

    Column
    width93
    Code Block
    themeConfluence
    VAR
        xUpdate        :    BOOL;    
        sIp            :    STRING;
        udiResult      :    UDINT;
        abyNewIp       :    ARRAY [0..3] OF BYTE := [192,168,99,198]; // Insert here the correct IP-Address of the Modbus_Slave_Device
    END_VAR




    Section
    Column
    width7

    Implementation

    Column
    width93
    Code Block
    themeConfluence
    sIp := IoDrvEthernet.IPARRAY_TO_IPSTRING(Modbus_TCP_Slave.ComSettings.ipAddress);
    Modbus_TCP_Slave.xConfirmError := FALSE;
    
    IF xUpdate THEN
        xUpdate := FALSE;    
        udiResult := Modbus_TCP_Slave.UpdateCommunicationSettings(ipAddress := abyNewIp, uiPort := 502);    
        Modbus_TCP_Slave.xConfirmError := TRUE;
    END_IF





  • After starting the project, a connection cannot be established.

    Image Added

  • Set the variable xUpdate  to TRUE so that the new IP address is passed.

    Image Added

Note

Resetting to an invalid IP address is not possible.
The Modbus component has to be deactivated first.
This is done by means of the "Enable" property which is available only after activating the device diagnostics.