WinCC timer using the method described

1, Timer Functions2, the script describes the timer3, using a script to achieve more timer function3.1 The whole point of the archiveAvoid initial script execution and delayed implementation of the script 1:00 activated 3.2 WinCC projectTimer Functions
    
WinCC timer can make use of WinCC in accordance with the specified time period, or to perform tasks, such as archiving cycle execution variables at a specified point in time when you print reports Global Script or conditions are met. WinCC has provided some simple timer meet most timing. However, in some cases, WinCC provides timer can not meet our needs, then we can script provided by WinCC interface timing function programmatically, because the script itself either directly WinCC can call other functions, such as report printing It can also be used to control other functions executed by the intermediate variables, such as by setting / resetting archive control variable to trigger variable record implementation. WinCC provides C scripts and VBS scripts, this paper mainly to the scripting example to describe the global C to achieve timing functions.Script 2 presentation timer
 
Since the Global Script can be programmed to control other functions performed, the first look at the trigger for the global script:

Use timers and into Script Triggers use variables, the timer cycle is divided into executive and non-cycle execution time, such as once per minute cycles to execute the script belongs, designated to perform a non-periodic part of the implementation of October 1, 2012. Use variable triggers the script, that is, when the variable changes, the script is executed once, while variable capture can be recycled according to the specified collection period, or according to changes in the collection, according to the actual change is a 1 second collection variable.3 Use the timer function more scripts
   
Use the script itself timer can be programmed in the script way to achieve more other timing functions.
3.1 The whole point of the archive

    WinCC provides a variable archiving, archiving and tag archive is divided into non-periodic filing period, regardless of period or cycle archiving archiving, all they can through some script variables or return values ​​to control the archive, for example: the whole point of the archive. The following settings combine WinCC script to achieve a point in the entire archive, the archive is stopped five minutes after archiving, that only the first five minutes of each hour archiving data.
    
Software Environment: Windows 7 Professional Service Pack1, WinCC V7.0 SP3
    
Archive name: ProcessValueArchive
    
Archive tags: NewTag
    
Archiving cycle: 1 minute
    
Archive control variables startarchive
    
C script trigger period: 10 seconds
    
Script code:

#include “apdefap.h”
intgscAction( void )
{
    #pragma option(mbcs)
    #pragma code (“kernel32.dll”);
    void GetLocalTime (SYSTEMTIME* lpst);
    #pragma code();
      SYSTEMTIME time;
      int  t1;
      GetLocalTime(&time);
      t1=time.wMinute;
if(t1==00)
      {
                  SetTagBit(“startarchive”,1); 
       }
     if(t1==05)
      {
                  SetTagBit(“startarchive”,0);   
 }
return0;
}

   

     

 Similarly, on the basis of the above script to make changes, you can achieve a specified point in time to print the report in, call the following function as long as the trigger condition is met:
        RPTJobPrint ( “Myprintjob”);
       Myprintjob pre-created for the print job.
        The main part of the foot is to obtain the current time, the script under the surface is achieved to get the current time and get respectively year, month, day, hour, minute, second, a few features milliseconds week.

     Varname1 to Varname8 to WinCC internal variables. If it displayed on a WinCC screen, since the format of the default I / O field is 999.99, should Varname1 display format changed to 9999.

#include “apdefap.h”
intgscAction( void )
{
          #pragma option(mbcs)

          #pragma code (“kernel32.dll”);
             void GetLocalTime (SYSTEMTIME* lpst);
         #pragma code();
         SYSTEMTIME time;
            GetLocalTime(&time);
             SetTagWord(“Varname1”,time.wYear);
           SetTagWord(“Varname2”,time.wMonth);
           SetTagWord(“Varname3”,time.wDayOfWeek);
           SetTagWord(“Varname4”,time.wDay);
           SetTagWord(“Varname5”,time.wHour);
           SetTagWord(“Varname6”,time.wMinute);
           SetTagWord(“Varname7”,time.wSecond);
           SetTagWord(“Varname8”,time.wMilliseconds);
  return 0;
}

Set or read the system time function is as follows:
        
SetSystemTime
        
SetLocalTime
        
GetSystemTime
        
GetLocalTime
    
The local computer system time and Greenwich time is different. Function “SetSystemTime / GetSystemTime” is used to set or read Greenwich Mean Time.
   
Function “SetLocalTime / GetLocalTime” is used to set or read the local computer time.
  
Two kinds of time will vary depending on geography and time zone changes. Both functions use the same method.
  
Avoid initial script execution and delayed implementation of the script when 3.2 WinCC project is active
    
Global Script activated when the project is to be performed once, in some cases, need to avoid implementation of the script, the script will use to judge. For example, you can create a WinCC internal Boolean variable flag, the script is as follows:
  
#include “apdefap.h”intgscAction (void){
      
#pragma option (mbcs)

      if (GetTagBit ( “flag”) == 1)
              
SetTagWord ( “NewTag”, 1); // write code that corresponds to their own needs.
     
else
              
SetTagBit ( “flag”, 1); // Return-Type: BOOLreturn0;}
    
In addition to avoiding trigger script execution when the project is running activated, we can also () function execution delayed by Sleep pace, such as five minutes after power began to execute the script specific functions, as follows:
  
#include “apdefap.h”intgscAction (void){
        
#pragma option (mbcs)
 

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.