rchTimeGet (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Firmware version:

1.50 / 1.00.00


This function requests the current time, expressed as seconds since 1980-1-1 00:00:00 (LINSEC), from the RTCU Communication Hub.

The time requested can be either UTC or the Local time of the server.

This function is functionally identical to and interchangeable with the gwTimeGet function.

 

Note: the time service functionality must be available and enabled in the connected RTCU Communication Hub.

 

 

Input:        

UTC : BOOL (Default FALSE)

The format of the time fetched from the RTCU Communication Hub.

TRUE:

Requests the UTC time.

FALSE:

Requests the Local time.

 

Returns: DINT

The current time as seconds since 1980-1-1 00:00:00 (LINSEC).

0

- Error retrieving the time.

 

Declaration:

FUNCTION rchTimeGet : DINT;
VAR_INPUT
   UTC : BOOL;
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
 
VAR_INPUT
   update : BOOL;
END_VAR;
 
PROGRAM TimeTest;
VAR
   upd_old : BOOL;
   time    : DINT;
END_VAR;
 
   // Init cellular network
   gsmPower(power:=ON);
   netOpen(iface:=1);
 
   DebugMsg(message:="Program running");
 
BEGIN
   ...
   // Update device clock
   IF update AND NOT upd_old THEN
      // Get time
      time := rchTimeGet(UTC := TRUE);
      // Set curent time
      IF time > 0 THEN
         clockSet(linsec := time);
      END_IF;
   END_IF;
   upd_old := update;
END;
END_PROGRAM;