netGetStatistics (Functionblock)

Top  Previous  Next

Architecture:

NX32L

Firmware version:

2.27.00


This returns the current statistics for a network interface.

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.

The statistics for some interfaces will be reset when the interface is opened or when the device is reset. netGetStatisticsAcc can be used to get statistics that does not automatically reset.

 

Input:

iface : SINT

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

 

Output:

status : SINT;

0 = No valid statistics found for this interface. The other fields have not been updated.

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.

Sum of the following errors:

 

rx_length_errors : DINT

The number of packets dropped due to invalid length.

 

rx_over_errors : DINT

The number of packets dropped due to overflow.

 

rx_crc_errors : DINT

The number of packets received with a CRC error.

 

rx_frame_errors : DINT

Receiver frame alignment errors.

 

rx_fifo_errors : DINT

Receive fifo error count.

 

rx_missed_errors : DINT

The number of packets missed by the host.

 

 

tx_errors : DINT

The total number of transmit problems.

Sum of the following errors:

 

tx_aborted_errors : DINT

The number of discarded frames.

 

tx_carrier_errors : DINT

The number of frame transmission errors due to loss of carrier.

 

tx_fifo_errors : DINT

The number of frame transmission errors due to FIFO underrun/underflow.

 

tx_heartbeat_errors : DINT

The number of heartbeat errors.

 

tx_window_errors : DINT

The number of frame transmission errors due to late collisions.

 

multicast : DINT

The number of multicast packets received.

 

collisions : DINT

The number of collisions during packet transmissions.

 

 

Declaration:

 
FUNCTION_BLOCK netGetStatistics;
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_length_errors   : DINT;
   rx_over_errors     : DINT;
   rx_crc_errors      : DINT;
   rx_frame_errors    : DINT;
   rx_fifo_errors     : DINT;
   rx_missed_errors   : DINT;
   tx_aborted_errors  : DINT;
   tx_carrier_errors  : DINT;
   tx_fifo_errors     : DINT;
   tx_heartbeat_errorsDINT;
   tx_window_errors   : DINT;
   rx_compressed      : DINT;
   tx_compressed      : DINT;
END_VAR;
 

Example:

INCLUDE rtcu.inc
VAR
   netStats :  netGetStatistics;
   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;