FB_SetTimeZoneInformation

FB_SetTimeZoneInformation 1:

This function block can be used to modify or set the time zone settings of the operating system.

FB_SetTimeZoneInformation 2:

The operating system may change some time settings after the new time zone settings were set. The time may have to be reset. The time can be set with the function block: NT_SetLocalTime.

VAR_INPUT

VAR_INPUT
    sNetID     : T_AmsNetID;
    tzInfo     : ST_TimeZoneInformation;
    bExecute   : BOOL;
    tTimeout   : TIME := DEFAULT_ADS_TIMEOUT;
END_VAR

sNetID: Here a string containing the network address of the TwinCAT Computer can be given, whose time zone setting is to be changed. The string can also be empty for the local computer.    

tzInfo: Structure with the new time zone settings to be set.

bExecute: The command is executed with a positive edge at the input

tTimeOut: Maximum time allowed for the execution of the ADS command.

 

VAR_OUTPUT

VAR_OUTPUT
    bBusy       : BOOL;
    bError      : BOOL;
    nErrId      : UDINT;
END_VAR

bBusy: When the function block is activated this output is set. It remains set until and acknowledgement is received.

bError:  If an ADS error should occur during the execution of the command, then this output is set, after the bBusy output has been reset. 

nErrId: When the bError output is set, this variable supplies the ADS error or the command-specific error code (table).

Example in ST:

The time zone "West Europa Standard Time" is to be set on the local TwinCAT System.  As example the constant WEST_EUROPE_TZI with the required parameter values is declared in the PLC library. To configure other time zones the  tzInfo input of the function block has to be allocated with the accordant values (see description of ST_TimeZoneInformation structure).

VAR_GLOBAL CONSTANT
...
    (* West Europa Standard Time Zone settings *)
    WEST_EUROPE_TZI : ST_TimeZoneInformation := (bias:=-60,
                    standardName:='W. Europe Standard Time',
                    standardDate:=(wYear:=0,wMonth:=10,wDayOfWeek:=0,wDay:=5,wHour:=3),
                    standardBias:=0,
                    daylightName:='W. Europe Daylight Time',
                    daylightDate:=(wYear:=0,wMonth:=3,wDayOfWeek:=0,wDay:=5,wHour:=2),
                    daylightBias:=-60);
...
ENd_VAR

Declaration part:

PROGRAM MAIN
VAR
    fbGet : FB_GetTimeZoneInformation;
    fbSet : FB_SetTimeZoneInformation;

    tzi_get : ST_TimeZoneInformation;
    tzID : E_TimeZoneID;

    bGet : BOOL := TRUE;
    bSet : BOOL := FALSE;
END_VAR

The desired time zone setting is set with a rising edge at the bSet  variable. To check the current settings the settings can be read with a rising edge at the bGet variable.

IF bGet THEN
    bGet := FALSE;
    fbGet(bExecute := TRUE);
ELSE
    fbGet(bExecute := FALSE, tzInfo => tzi_get, tzID => tzID );
END_IF

IF bSet THEN
    bSet := FALSE;
    fbSet( bExecute := TRUE, tzInfo := WEST_EUROPE_TZI );
ELSE
    fbSet( bExecute := FALSE );
END_IF

 

Further time, time zone functions and function blocks:

FB_TzSpecificLocalTimeToSystemTime, FB_TzSpecificLocalTimeToFileTime, FB_SystemTimeToTzSpecificLocalTime, FB_FileTimeTimeToTzSpecificLocalTime, FB_GetTimeZoneInformation, FB_SetTimeZoneInformation, NT_SetLocalTime, NT_GetTime, NT_SetTimeToRTCTime, F_TranslateFileTimeBias, FB_LocalSystemTime

Requirements

Development Environment

Target System

PLC libraries to include

TwinCAT v2.10.0 Build > 1319

PC or CX (x86)
CX (ARM)

TcUtilities.Lib