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

Change Ethernet settings from IEC-code

e.kislov
2018-12-18
2019-11-25
  • e.kislov - 2018-12-18

    Hi. In FAQ there is nice manual how to change Modbus TCP Slave network settings from IEC-code:
    https://faq.codesys.com/display/CDSFAQ/ ... IP+Address

    Is this same way to change Ethernet adapter settings? (IP, mask, gateway)
    I mean, settings for component IoDrvEthernet.

     
  • e.kislov - 2018-12-18

    Thanks for intention to help, but...

    First link it's how to get client IP, not PLC IP. Besides, I know how to get PLC IP, I need to set it.
    Second link it's about Ethernet/IP, but I need info how to set settings for common Ethernet adapter (IoDrvEthernet).

    In more detail: I see properties IoDrvEthernet.IPAddress and IoDrvEthernet.IPAddressConfigured, but I don't know is it possible to use it for my task and which one I should used (if first answer yes). I also can't test it right now.

    I would be to happy hear some comments from Edwin or Marcel, if they find time in this last pre-holiday days.

     
  • eschwellinger

    eschwellinger - 2018-12-19

    Hi,
    sure, you need to enable it in you config file:
    example:
    /etc/CODESYSControl_User.cfg

    [SysSocket]
    Adapter.0.Name="eth1"
    Adapter.0.EnableSetIpAndMask=1

    then in the application:
    You could ( for testing purpose) add the ethernet connector and enable the change..
    Sure later you do this by iec code.

            a: INT;
       AdapterInfo : SOCK_ADAPTER_INFORMATION;
       hAdapter: RTS_IEC_HANDLE;
       rResult : RTS_IEC_RESULT;
       udiStructSize : UDINT;
       ERR_OK: UDINT;
       wszAdapter : WSTRING := "br1";
       IP: INADDR;
       Mask: INADDR;
       bSet: BOOL;
    
    a:=a+1;
    // add the following section in "/etc/CODESYSControl_User.cfg"
    //[SysSocket]
    //Adapter.0.Name="br1"
    //Adapter.0.EnableSetIpAndMask=1
    (* Test von SysSockGetFirstAdapterInfo/SysSockGetNextAdapterInfo *)
    udiStructSize := SIZEOF(AdapterInfo);
    hAdapter := SysSockGetFirstAdapterInfo(ADR(AdapterInfo), ADR(udiStructSize), ADR(rResult));
    WHILE rResult = ERR_OK DO
       hAdapter := SysSockGetNextAdapterInfo(hAdapter, ADR(AdapterInfo), ADR(udiStructSize), ADR(rResult));
    END_WHILE
    (* Test von SysSockSetIpAddressAndNetMask *)
    IF bSet = TRUE THEN
       bSet := FALSE;
       IP.ulAddr := 16#01010140;
       Mask.ulAddr := 16#0000FFFF;
       
       rResult := SysSockSetIpAddressAndNetMask(wszAdapter, IP, Mask);
    END_IF
    

    BR
    Edwin

    IMG: ChangeIpSettings.png

     
    👍
    1
  • e.kislov - 2018-12-20

    Thank you, Edwin, and wish a nice holidays. Will try it.
    Also vote for CDS-63965 as more simple way.

     
  • alext - 2019-11-25

    It is important to know that the Ethernet adapter must be configured for static IP addressing.

     

Log in to post a comment.