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



  • Adapt the POU PLC_PRG as follows:


    Declaration

    VAR
        xCheckDevice    :    BOOL;
        sIpAddr         :    STRING := '192.168.99.198';
        udiReplayAverage:    UDINT;
        tTimeout        :    TIME := T#50MS; // Must greather than 25 ms => minimum in the function!!
        xConnected      :    BOOL;
    END_VAR

    Implementierung

    IF xCheckDevice THEN
        xCheckDevice := FALSE;
        IF SysSocket.SysSockPing(szIPAddress := sIpAddr, ulTimeout := TIME_TO_UDINT(tTimeout), pulReplyTime := ADR(udiReplayAverage)) = 0 THEN
            xConnected := TRUE;
        ELSE
            xConnected := FALSE;    
        END_IF
    END_IF

    Depending on the operating system, the function has different minimum runtimes.
    Therefore, timeout times of 25 milliseconds or more should be used.
    In this way, it is appropriate to outsource the function call in a separate task whenever possible.

  • Start the project and set the xCheckDevice variable to TRUE.