grig100 Member 3


Joined: 01 Jan 2015 Posts: 752
|
Posted: 31/05/2016 17:53 Post subject: How do you access the system time with WinCC Global Script? |
|
|
How do you access the system time with WinCC Global Script?
If you want to use this script in the operating system Windows 7 or higher, you have to disable the user account control. This might cause disadvantages which you would have to weigh up against your requirements.
The user account control, which has been tightened in Windows 7, blocks the system functions below.
Proceed as follows to prevent this restriction.
Under Start > Search Bar you enter "uac" and start the user account control (UAC stands for User Account Control). The "Settings for User Account Control" window opens. The settings are displayed as a safety governor.
Pull the safety governor to "Never report" and confirm the setting with "OK".
Restart the computer.
Instructions
You can set or read the system time with the following functions:
| Code: | SetSystemTime
SetLocalTime
GetSystemTime
GetLocalTime |
A distinction is made in the system between the local computer time and Greenwich Mean Time. You use the "SetSystemTime / GetSystemTime" functions to set or read Greenwich Mean Time.
You use the "SetLocalTime / GetLocalTime" functions to set or read the local computer time.
Both times vary on account of the differing geographical time zones, as well as due to the change between winter time and summer time. Use of the functions is completely identical.
The functions for determining or setting the local computer time are Windows functions and, thus, independent of the WinCC functions "GetLocalTimeString" and "GetLocalTime" in older versions of WinCC.
The following examples show how the local computer time is read or set in WinCC.
Read the time and store it in Word variables
| Code: | #pragma code("kernel32.dll")
VOID GetLocalTime(SYSTEMTIME *lpst);
#pragma code();
SYSTEMTIME zeit;
GetLocalTime(&zeit);
SetTagWord("varname",zeit.wYear);
SetTagWord("varname",zeit.wMonth);
SetTagWord("varname",zeit.wDayOfWeek);
SetTagWord("varname",zeit.wDay);
SetTagWord("varname",zeit.wHour);
SetTagWord("varname",zeit.wMinute);
SetTagWord("varname",zeit.wSecond);
SetTagWord("varname",zeit.wMilliseconds);
|
Read the time and store it in raw data variables
| Code: | #pragma code("kernel32.dll")
VOID GetLocalTime(SYSTEMTIME *lpst);
#pragma code();
SYSTEMTIME zeit;
GetLocalTime(&zeit);
SetTagRaw("varname",(Byte*)&zeit,sizeof (SYSTEMTIME)); |
Set the time using Word variables
| Code: | #pragma code("kernel32.dll")
VOID SetLocalTime(SYSTEMTIME *lpst);
#pragma code();
SYSTEMTIME zeit;
zeit.wYear=GetTagWord("varname");
zeit.wMonth=GetTagWord("varname");
zeit.wDayOfWeek=GetTagWord("varname");
zeit.wDay=GetTagWord("varname");
zeit.wHour=GetTagWord("varname");
zeit.wMinute=GetTagWord("varname");
zeit.wSecond=GetTagWord("varname");
zeit.wMilliseconds=GetTagWord("varname");
SetLocalTime(&zeit); |
Set the time using a raw data variable
| Code: | #pragma code("kernel32.dll")
VOID SetLocalTime(SYSTEMTIME *lpst);
#pragma code();
SYSTEMTIME zeit;
GetTagRaw("varname",(BYTE*)&zeit,sizeof (SYSTEMTIME));
SetLocalTime(&zeit);
|
|
|