You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

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 Network scan.



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

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


  • 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.



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

  • Adapt the POU PLC_PRG as follows:


    Declaration

    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

    Implementation

    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.



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



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.



  • No labels