netGetStatisticsAcc (Functionblock)

Top  Previous  Next

Architecture:

NX32L

Firmware version:

2.50.00


This returns the accumulated statistics for a network interface.

These statistics are persistent across reboots and closing of interfaces.

Depending on the kind of interface and the status, some variables may be empty.

The variables will wrap around when reaching the max value(2147483647). This means that fast-growing values such as rx_bytes will turn negative when the max value is reached, which the application must handle.

One way to handle it is to reset the statistics once a value has reached above a limit and store the previous values somewhere else.

 

Note that the statistics is updated periodically.

 

Input:

iface : SINT

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

 

reset : BOOL (default FALSE)

Set to true to reset the statistics to 0 after reading the current values.

 

 

Output:

status : SINT;

0 = No valid statistics found for this interface. The other fields have not been updated. This can happen if the interface is not present.

1 = The statistics are valid.

 

rx_packets : DINT

The number of good packets received by the interface.

 

tx_packets : DINT

The number of successfully sent packets.

 

rx_bytes : DINT

The number of good received bytes.

 

tx_bytes : DINT

The number of good transmitted bytes.

 

rx_dropped : DINT

The number of packets received but not processed.

 

tx_dropped : DINT

The number of packets dropped on their way to transmission.

 

rx_compressed : DINT

The number of received compressed frames(Cellular only)

 

tx_compressed : DINT

The number of transmitted compressed frames(Cellular only)

 

rx_errors : DINT

The total number of bad packets received on this network.

 

tx_errors : DINT

The total number of transmit problems.

 

multicast : DINT

The number of multicast packets received.

 

collisions : DINT

The number of collisions during packet transmissions.

 

 

Declaration:

 
FUNCTION_BLOCK netGetStatisticsAcc;
VAR_INPUT
   iface              : SINT;
END_VAR;
VAR_OUTPUT
   status             : SINT;
   rx_packets         : DINT;
   tx_packets         : DINT;
   rx_bytes           : DINT;
   tx_bytes           : DINT;
   rx_errors          : DINT;
   tx_errors          : DINT;
   rx_dropped         : DINT;
   tx_dropped         : DINT;
   multicast          : DINT;
   collisions         : DINT;
   rx_compressed      : DINT;
   tx_compressed      : DINT;
END_VAR;
 

Example:

INCLUDE rtcu.inc
VAR
   netStats :  netGetStatisticsAcc;
   iface    :  SINT := 2// Network interface to use: 1 for Cellular, 2 for LAN.
END_VAR;
 
FUNCTION printStats
   netStats(iface:=iface);
   DebugFmt(message:="Network interface \1:", v1 := iface);
   DebugFmt(message:=" Status \1", v1 := netStats.status);
   IF netStats.status > 1 THEN
         DebugFmt(message:=" RX packets: \4", v4:=netStats.rx_packets);
         DebugFmt(message:=" TX packets: \4", v4:=netStats.tx_packets);
         DebugFmt(message:=" RX bytes:   \4", v4:=netStats.rx_bytes);
         DebugFmt(message:=" TX bytes:   \4", v4:=netStats.tx_bytes);
         DebugFmt(message:=" RX errors:  \4", v4:=netStats.rx_errors);
         DebugFmt(message:=" TX errors:  \4", v4:=netStats.tx_errors);
         DebugFmt(message:=" RX dropped: \4", v4:=netStats.rx_dropped);
         DebugFmt(message:=" TX dropped: \4", v4:=netStats.tx_dropped);
   END_IF;
END_FUNCTION;
 
PROGRAM test;
VAR
   rc : INT;
END_VAR;
   IF iface = 1 THEN
      // Turn on power to GSM module
      gsmPower(power:=ON);
   END_IF;
   IF NOT netPresent(iface:=ifaceTHEN
      DebugFmt(message:="Network interface \1 is not available", v1:=iface);
      WHILE TRUE DO
         Sleep(delay:=5000);
      END_WHILE;
   END_IF;
   rc := netOpen(iface:=iface);
   DebugFmt(message:="netOpen: \1", v1:=rc);
   WHILE NOT netConnected(iface:=ifaceDO
      DebugMsg(message:="Waiting for network connection");
      Sleep(delay:=2500);
   END_WHILE;
   // Print network statistics
   printStats();
   // Network is ready
BEGIN
 
   //...
 
END;
END_PROGRAM;