netPresent (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

All

Firmware version:

4.34 / 1.00.00


Returns information about whether a network interface is present in the device.

 

 

Input:

iface : SINT

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

 

Returns: BOOL

true if the network interface is present, false if not.

 

 

Declaration:

FUNCTION netPresent : BOOL;
VAR_INPUT
  iface : SINT;
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
//  These are the global variables of the program
VAR
  netInfo  : netGetInformation;
  iface    : SINT := 2; // Network interface to use: 1 for Mobile, 2 for LAN.
END_VAR;
 
FUNCTION printInfo
  netInfo(iface:=iface);
  DebugFmt(message:="Network interface \1:", v1 := iface);
  DebugFmt(message:=" Status \1", v1 := netInfo.status);
  IF netInfo.status > 1 THEN
    DebugMsg(message:=" Phy addr " + netInfo.phy_addr);
    IF netInfo.dhcp THEN
        DebugMsg(message:=" Dynamic IP address");
    ELSE
        DebugMsg(message:=" Static IP address");
    END_IF;
    DebugMsg(message:=" IP addr " + sockIPToName(ip := netInfo.ip));
    DebugMsg(message:=" Mask    " + sockIPToName(ip := netInfo.subnetMask));
    DebugMsg(message:=" Gateway " + sockIPToName(ip := netInfo.gateway));
    IF netInfo.AutoDNS THEN
        DebugMsg(message:=" Automatic DNS");
    ELSE
        DebugMsg(message:=" Manual DNS");
    END_IF;
    DebugMsg(message:=" DNS1    " + sockIPToName(ip := netInfo.DNS1));
    DebugMsg(message:=" DNS2    " + sockIPToName(ip := netInfo.DNS2));
  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 information
  printInfo();
  // Network is ready
BEGIN
 
  //...
 
END;
END_PROGRAM;