netPingS (Function)

Top  Previous  Next

Architecture:

NX32 / NX32L

Firmware version:

5.12 / 1.62.00


This function sends a ICMP-echo (ping) packet to a designated host IP address and returns the reply time.

To get more detailed statistics on NX32L devices, the alternative function netPing can be used.

 

On NX32 devices this function only supports iface=1 (Cellular network).
 
 

Input:

IP : DINT

The IP address of the host.

 

iface : SINT

The network interface to use. 1 = Cellular network, 2 = LAN network, etc. (See Network)

 

timeout : UINT (default 500)

The time to wait for a reply from the host in milliseconds.

 

Returns: INT

1

- Success.

0

- Not available.

-1

- Timeout.

-2

- Invalid parameter.

-3

- The network interface is not available.

-4

- Communication error.

 

Declaration:

 
FUNCTION netPingS : INT;
VAR_INPUT
   ip             : DINT;
   iface          : SINT := 1;
   timeout        : UINT := 500;
END_VAR;
 

Example:

INCLUDE rtcu.inc
 
VAR
   iface    : SINT := 1;
END_VAR;
 
PROGRAM pingtest;
VAR
   rc : INT;
END_VAR;
 
// Network
rc := netOpen(iface:=iface);
DebugFmt(message:="netOpen (rc=\1)",v1:=rc);
WHILE NOT netConnected(iface:=ifaceDO
   Sleep(delay:=2000);
END_WHILE;
 
// Ping host
rc := netPingS(iface:=ifaceip:=sockIPFromName(str:="gw.rtcu.dk"), timeout:=1000);
DebugFmt(message := "netPingS. reply time=\1)", v1 := rc);
END_PROGRAM;