This function requests the current time expressed as seconds since 1980-1-1 00:00:00 (LINSEC), from the cellular network.
Note:
Not all networks offer a time-service. The time information is transmitted with a variable frequency by the network.
Input:
UTC : BOOL (default: FALSE)
Specifies whether the local-time or UTC time should be returned.
Not all devices supports UTC time and will therefore return the local time in all cases.
Returns: DINT
The current time as seconds since 1980-1-1 00:00:00 (LINSEC).
0
|
- Updated network time is currently not available.
|
-1
|
- Network time not supported by device.
|
-2
|
- Not connected to the network.
|
-3
|
- General error.
|
Declaration:
FUNCTION gsmNetworkTime : INT;
VAR_INPUT
UTC : BOOL;
END_VAR;
Example:
INCLUDE rtcu.inc
VAR_INPUT
update : BOOL;
END_VAR;
PROGRAM test;
VAR
upd_old : BOOL;
time : DINT;
END_VAR;
gsmPower(power:=ON);
DebugMsg(message:="Program running");
BEGIN
...
IF update AND NOT upd_old THEN
time := gsmNetworkTime();
IF time > 0 THEN
clockSet(linsec := time);
END_IF;
END_IF;
upd_old := update;
END;
END_PROGRAM;
|