This function tells if a connection to the network has been established.
Input:
iface : SINT
The network interface to query. 0 = Any network, 1 = Mobile network, 2 = LAN network, etc. (See Network)
Returns: BOOL
true if connection to the network has been established, false if not.
Declaration:
FUNCTION netConnected : BOOL;
VAR_INPUT
iface : SINT;
END_VAR;
Example:
INCLUDE rtcu.inc
VAR
netInfo : netGetInformation;
iface : SINT := 2;
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
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;
printInfo();
BEGIN
END;
END_PROGRAM;
|