Contents
Page
Training Training aims ............ ................. ........... ........... ........... ........... ........... ........... ........... ........... ........... ........... ........... ............ ........... ........... ............ ........... ........... ........... ........... ........... ........... ......
2
Global Script Script editors editors ............ ................. ........... ........... ........... ........... ........... ........... ........... ........... ........... ........... ........... ............ ........... ........... ............ ........... ........... ........... ........... ........
3
Global Script Script C editor editor ............ ................. ........... ........... ........... ........... ........... ........... ........... ........... ........... ........... ........... ............ ........... ........... ............ ........... ........... ........... .......... .....
4
Global Global Script Script C edito editorr Example Example of a functi function on ...... .......... ....... ....... ....... ...... ...... ....... ....... ...... ...... ...... ...... ...... ...... ...... ....... ....... ....... ....... ...... ...... ...... ...... ....... ...... ..
5
Global Script C editor editor Example Example of an action action ............ ................. ........... ........... ........... ........... ........... ........... ........... ........... ........... ........... ........... ............ ......... ...
6
Global Global Script Script VBS editor editor Example Example of a f unctio unction n ...... .......... ....... ....... ........ ....... ...... ...... ....... ....... ....... ........ ....... ...... ...... ....... ....... ....... ........ ....... ....... ........ ...... ..
7
Global Global Script Script VBS editor editor Example Example of an action ...... .......... ....... ...... ...... ....... ....... ....... ........ ....... ....... ........ ....... ...... ...... ....... ....... ....... ........ ....... ...... ...... ....... ......
8
Exercis Exercise e 1 (optio (optiona nal): l): Global Global Script Script ....... .......... ...... ...... ...... ....... ....... ....... ....... ...... ...... ....... ....... ..... ...... ....... ...... ...... ...... ...... ....... ....... ....... ....... ...... ...... ...... ...... ....... ....... ...
9
SITRAIN Train Trainin ing g for for Automation Automation and Industrial Industrial Solutions Solutions
Page 1
ST-BWINCCS Global Script
The participant will :
Get to know the differences between the various types of function
Be able to create simple functions
Be able to create actions for background processing
SITRAIN Training for Automation and Industrial Solutions
Page 2
ST-BWINCCS Global Script
General
Global Script is a generic term for functions and actions with ANSI-C and VBS. A separate editor exists for each of the two programming languages. Acti on s are scripts that run in the background and that are independent of the currently selected picture. With actions, a trigger therefore needs to be defined. Many functions are made available as soon as WinCC is installed. Wi th the Global Script editors, however, you can write your own functions. Functions contain tasks that are repeated, f or example calculating a mean value. These functions are then called in other scripts. For this reason, no trigger can be defined here. In the figure above, you can see two simple functions for the addition of 2 values.
SITRAIN Training for Automation and Industrial Solutions
Page 3
ST-BWINCCS Global Script
Password
Self-created functions or actions can be gi ven a password to protect your own know-how. The entry of the password is made in the Info/Trigger box (ctrl + I or click on the clock symbol).
Acti on s
For the actions, there are two subfolders in the figure above. One folder with the computer name of the single-user station and "G lobal actions". With Wi nCC server-client configurations, there is one folder per computer. This means it is possible to specify for an action that it should, for example, only run on a specific computer.
SITRAIN Training for Automation and Industrial Solutions
Page 4
ST-BWINCCS Global Script
Creation
In the Global Script C editor, you can create your own functions. The example above has two parameters "a" and "b", both are of the type integer. The function has a return value also of the type integer: int Add_Function(int a, int b) If the function did not have a return value, the first line would appear as follows: void FunctionXYZ(int a, int b) With the return command, the result is returned to the calling location.
Use
The function can be called up in pictures or global C actions. In the example above, the call is at an I/O field in a picture.
Copying fun ction s between WinCC proj ects Project functions are stored in the "Library" subfolder of the WinCC project with the file extension *.fct. Similar to the pictures, they can be copied from one WinCC project to another. In this case, the function "Options/Regenerate Header" must be called in the target project in the Global Script C editor. Only after this are the copied functions visible in the editor.
SITRAIN Training for Automation and Industrial Solutions
Page 5
ST-BWINCCS Global Script
Global actio n
In the example above, a variable is incremented to 100 depending on the WinCC tag SimOnOff, the value then jumps back to zero. Since the trigger is fixed at one second, this action is started every second. In this case this is wanted and a tag trigger cannot be used here.
Computer properties When global actions need to be started, the component "Global Script Runtime" must be activated in the computer properties.
SITRAIN Training for Automation and Industrial Solutions
Page 6
ST-BWINCCS Global Script
Project modules Here, configuration engineers themselves can create new f unctions. Several functions can be contained in one modul e. The module VBS_Module1.bmo is located in the subfolder "ScriptLib" of the W inCC project. Standard modul es Once again, the configuration engineer can create new functions here. In contrast to project functions, cross-project standard procedures are available in all the projects located on the PC. Several functions can be contained in one m odule. Acti on s
See following page
Code templates
As in the VBS editor in the Graphics Designer
Example of a functi on
The function above calculates the sum of the transf erred parameters.
With the line "MyAddFunction = value1 + value2“ the sum is returned to the calli ng location. Sub or Function
Sub name1(Item) …
Function procedure1 …
End Sub
End Function
-> without return value
-> with return value
SITRAIN Training for Automation and Industrial Solutions
Page 7
ST-BWINCCS Global Script
Acti on s:
VB scripts that can run independently in the background of WinCC Runtime. The file extension for VB actions is *.bac. These files are located in the subf older "ScriptAct" of the WinCC project.
Computer properties When global actions need to be started, the component "Global Script Runtime" must be activated in the computer properties.
SITRAIN Training for Automation and Industrial Solutions
Page 8
ST-BWINCCS Global Script
SITRAIN Training for Automation and Industrial Solutions
Page 9
ST-BWINCCS Global Script