netGetStatistics (Functionblock)

Top  Previous  Next

Architecture:

NX32L

Device support:

All

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.

 

Input:

iface : SINT

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

 

Output:

status : SINT;

0 = Not 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_errors: DINT;
  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 Mobile, 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:=iface) THEN
    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:=iface) DO
    DebugMsg(message:="Waiting for network connection");
    Sleep(delay:=2500);
  END_WHILE;
  // Print network statistics
  printStats();
  // Network is ready
BEGIN
 
  //...
 
END;
END_PROGRAM;