C-Script for time & date sync with WinCC 6.0

userxyz

Member
Join Date
May 2002
Location
any
Posts
2,768
I don't really understand C. But because I understand Visual Basic a little bit, I think it can be understood.

what means: return 0, GetTagBitWait, #pragma code ("kernel32.dll"); can someone explain a bit how this simple code works ?
Oven_3_Flag is cyclic triggered hourly.

wgy this line is needed: SetTagBitWait("Oven_3_Flag", TRUE);





#include "apdefap.h"
int gscAction( void )
{
#pragma code ("kernel32.dll");
void GetLocalTime (SYSTEMTIME *lpst);
#pragma code ();
SYSTEMTIME time;
if(GetTagBitWait("Oven_3_Flag")==0)
{
GetLocalTime (&time);
SetTagByteWait("Oven_3_Year", (BYTE)(time.wYear-2000));
SetTagWordWait("Oven_3_Month", time.wMonth);
SetTagWordWait("Oven_3_Day", time.wDay);
SetTagWordWait("Oven_3_Hour", time.wHour);
SetTagWordWait("Oven_3_Minute", time.wMinute);
SetTagWordWait("Oven_3_Second", time.wSecond);
SetTagBitWait("Oven_3_Flag", TRUE);
}
return 0;
}
 
OK, it's been a while but here goes:

1) Return 0 means the function returns 0 to the calling application if it completes successfully. Often numbers other than zero are used to indicate a problem to the calling function.

2) "pragma" means a compiler-specific option. In this case, it looks like 32-bit Window specific options have been turned on. This may mean your long integers are all 64 rather than 32bit, for example.

3) What the code is doing is making system call to get a pointer to the system time object when the Oven_3_flag is equal to 0. Once a reference to this object (i.e. an address) is returned, the time struct members are accessed to copy their values to the appropriate tags.

Note that it is easy to get confused between the way GetLocalTime is declared with an argument that is an pointer, how it is called with an reference. Both are types of pointer to memory that are interchangeable here (a reference is just a fixed pointer).

The bracketed (byte) keyword indicates the data is being cast into the byte format.

Hope that helps... best guess from uni projects :)
 
Adding to Binaural:

When Oven_3_flag is zero it is set back to one and current date is copied into Oven_3's date structure. Some other processing must be involved which reads the Oven_3 date data and sets Oven_3_flag back to zero.
 

Similar Topics

Hi, In WinCC (v7.0) i've created object. To one property assigned C script which is triggered by TAG when changed. Is it possible choose...
Replies
5
Views
12,026
Hi! I need in WInCCflex write one script which does following: When i click on one button on one I/O Field must be displayed system time, and on...
Replies
2
Views
3,017
Hi! i have write some VBScript that check a plc variable (for example m100.0). When m100.0 raise to 1, the script read up to 50 tags and write...
Replies
8
Views
4,886
Hello, I am learning to create shapes and VB Scripts in HMIWeb Display Builder. I wanted to change color of my rounded rectangle by script. I...
Replies
0
Views
104
Hello, I have a quick question. I have been using scripts to change the color of buttons. The reason, I am usually using multiple hmiruntime.tags...
Replies
1
Views
99
Back
Top Bottom