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:

Time settings

The operating system may change some time settings after the new time zone settings were set.

The time can be reset with the function block NT_SetLocalTime.

FB_SetTimeZoneInformation 3: Inputs

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

Name

Type

Description

sNetID

T_AmsNetID

A string with the network address of the TwinCAT computer whose time zone configuration is to be changed can be specified here. For the local computer an empty string may be specified.

tzInfo

ST_TimeZoneInformation

Structure with the new time zone settings that are to be set.

bExecute

BOOL

The function block is enabled by a positive edge at this input.

tTimeout

TIME 

States the length of the timeout that may not be exceeded by execution of the ADS command.

FB_SetTimeZoneInformation 4: Outputs

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

Name

Type

Description

bBusy

BOOL

When the function block is enabled, this output is set and remains set until a feedback is received.

bError

BOOL

If an error occurs during the transmission of the command, this output is set after the bBusy output is reset.

nErrID

UDINT

Returns the ADS error number when the bError output is set.

Example:

On the local TwinCAT system the time zone: "Western Europe Standard Time" is to be set. As an example a constant: WEST_EUROPE_TZI with suitable parameter values was already declared in the PLC library. To configure other time zones, the tzInfo input of the function block must be assigned with corresponding values (see description of the 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

The 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

A rising edge at the bSet variables results in setting of the required time zone setting. For verification the current 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 and time zone functions and function blocks:

Requirements

Development environment

Target platform

PLC libraries to be integrated (category group)

TwinCAT v3.1.0

PC or CX (WES7/Win7/Win10: TC RT x86/x64, WEC6/7: TC RT x86, WEC7: TC CE7 ARMV7)

Tc2_Utilities (System)