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



  • Open the Library Manager and add the following libraries:
    • SysSocket
    • SM3_Shared
    • SysTypes2 Interfaces



  • Adapt the POU PLC_PRG as follows:


    Declaration

    VAR
        AdapterInfo     : SOCK_ADAPTER_INFORMATION;
        hAdapter        : RTS_IEC_HANDLE;
        udiStructSize   : UDINT := SIZEOF(AdapterInfo);
        rResult         : RTS_IEC_RESULT;
        sIpAddr         : STRING(15);
        sMacAddr        : STRING(17);
        xFirstAdapter   : BOOL;
        xReadInfo       : BOOL;    
    END_VAR

    Implementation

    IF xReadInfo THEN 
        xReadInfo := FALSE;
        xFirstAdapter := TRUE;
        rResult := 0;
        WHILE rResult = 0 DO    
            IF xFirstAdapter THEN
                hAdapter := SysSockGetFirstAdapterInfo(ADR(AdapterInfo), ADR(udiStructSize), ADR(rResult));
            ELSE    
                hAdapter := SysSockGetNextAdapterInfo(hAdapter, ADR(AdapterInfo), ADR(udiStructSize), ADR(rResult));
            END_IF
            IF rResult = 0 THEN
                sIpAddr := Standard.CONCAT(BYTE_TO_STRING(AdapterInfo.IpAddr.S_un_b.s_b1),'.');
                sIpAddr := Standard.CONCAT(sIpAddr,BYTE_TO_STRING(AdapterInfo.IpAddr.S_un_b.s_b2));
                sIpAddr := Standard.CONCAT(sIpAddr,'.');
                sIpAddr := Standard.CONCAT(sIpAddr,BYTE_TO_STRING(AdapterInfo.IpAddr.S_un_b.s_b3));
                sIpAddr := Standard.CONCAT(sIpAddr,'.');
                sIpAddr := Standard.CONCAT(sIpAddr,BYTE_TO_STRING(AdapterInfo.IpAddr.S_un_b.s_b4));
                sMacAddr := Standard.CONCAT(SM0.Byte_To_HexString(AdapterInfo.abyMac[0]),'-');
                sMacAddr := Standard.CONCAT(sMacAddr,SM0.Byte_To_HexString(AdapterInfo.abyMac[1]));
                sMacAddr := Standard.CONCAT(sMacAddr,'-');
                sMacAddr := Standard.CONCAT(sMacAddr,SM0.Byte_To_HexString(AdapterInfo.abyMac[2]));
                sMacAddr := Standard.CONCAT(sMacAddr,'-');
                sMacAddr := Standard.CONCAT(sMacAddr,SM0.Byte_To_HexString(AdapterInfo.abyMac[3]));
                sMacAddr := Standard.CONCAT(sMacAddr,'-');
                sMacAddr := Standard.CONCAT(sMacAddr,SM0.Byte_To_HexString(AdapterInfo.abyMac[4]));
                sMacAddr := Standard.CONCAT(sMacAddr,'-');
                sMacAddr := Standard.CONCAT(sMacAddr,SM0.Byte_To_HexString(AdapterInfo.abyMac[5]));
            END_IF
            xFirstAdapter := FALSE;    
        END_WHILE
    END_IF


  • Start the project and set a breakpoint in line 6 of the POU PLC_PRG.



  • After setting the xReadInfo variable, the variables are read for each adapter: