Background Processing (Global Script) : Sitrain
Background Processing (Global Script) : Sitrain
SITRAIN
ST-BWINCCS /GlobalScript Page 1 Siemens AG © 2007
Contents Page
Objectives .…..................................................................................................................................... 2
Global Script C Actions and Functions ..…….................................................................................... 3
Example of a Project Function and/or a Standard Function ............................................................. 4
Background Processing (Actions) with Global Script ……................................................................. 5
Example with Functions from DLLs ................................................................................................... 6
Global Script VBS Actions and Procedures 1/2 ……......................................................................... 7
Global Script VBS Actions and Procedures 2/2 ……......................................................................... 8
Example of a VBS Project Function ......……..................................................................................... 9
- Project Functions
- Standard Functions
- Internal Functions
- Project-wide Actions
- Project Modules
SITRAIN
ST-BWINCCS /GlobalScript Page 2 Siemens AG © 2007
SITRAIN
ST-BWINCCS /GlobalScript Page 3 Siemens AG © 2007
General Information Global Script is the general term for C functions and actions. There is a series of
C functions available for programming extensive actions in WinCC. These
C functions are divided into groups and can be used both in the Graphics Designer
as well as to a certain extent in Global Script.
Project Functions All project-specific functions are combined under this header. The functions are
applicable within the project (function library).
Standard Functions
This is where functions are located that can be used for more than one project.
Pre-defined functions are present that can be expanded by your functions.
Internal Functions The system provides the functions listed here. The user can not change the
internal functions. These functions contain all basic functions necessary for
processing WinCC objects. These functions also include all the functions in the
C standard library.
There is a subdivision into:
- alarm Functions for receiving and processing individual messages.
- allocate Functions for dynamic memory management (required if the return
value is a character string, for example).
- c_bib Standard C library functions.
- graphics Functions for reading and manipulating object properties
of individual WinCC objects.
- tag Functions for reading and writing tags from the data manager.
- wincc Functions for influencing the individual WinCC Runtime components.
Actions Actions are available only in the Global Script. This is where actions are defined
that run in the background and are not connected directly with the selected WinCC
object (screen, screen window, graphic object, etc.).
Procedure The function is created in Global Script after the method of functioning and the
parameters to be transferred have been clarified.
After the function has been saved in the project functions or standard functions, it
can be used in the Graphics Designer at various locations and with various
parameters. (Functions you write yourself can not be used in Global Script.)
The advantage of central storage is how easy it is to make changes and to
maintain the function. Changes only have to be carried out at one location and are
immediately available at all call-up locations (as long as the transfer parameters
do not change).
Parameters are transferred in the C syntax.
Function Call The call of the function named above has the following appearance in the
Graphics Designer.
For example, Setting Bit 2 in a word:
Events/ mouse/ left mouse button/ C function...
BitSet ( 1, "MotorStatus", 2);
This sets Bit 2 in the "MotorStatus" tag.
To reset the bit, you have to call the same function with the paramaters:
BitSet ( 0, "MotorStatus", 2);
Operating hours.PAS
WORD HOUR, MINUTE;
BYTE Z_ON;
if (Z_ON) {
MINUTE = GetTagWord ("Minutes");
MINUTE = MINUTE + 1;
SetTagWord ("Minutes", MINUTE);
SITRAIN
ST-BWINCCS /GlobalScript Page 5 Siemens AG © 2007
General Information You have a Project-wide ActionSystem (PAS) available in WinCC for actions
independent of the screen. These actions run in the background and can be
started cyclically (time trigger), acyclically (at a certain time), or even dependent
on an event (tag). These actions serve to implement actions for an entire project.
The individual actions are created in the Global Script Editor.
SITRAIN
ST-BWINCCS /GlobalScript Page 6 Siemens AG © 2007
General Information Action programming from WinCC offers a multitude of generation possibilities. It is
also possible to access external functions stored in DLLs, for example, within the
C action.
These DLLs can be both standard DLLs as well as function libraries you create
yourself.
Using a function from a DLL is especially recommended where extensive
calculations must be carried out. Because the code is already stored in an
executable way in the DLL and does not have to be interpreted at runtime, there is
a significantly faster processing speed for extensive calculations.
Example In the example above, nothing more is done for the DLL function than processing a
loop from a start value to an end value.
The intermediate results are output in a diagnostics window.
In a direct comparison, you do not see a significant time advantage in using DLL
functions until there are very many operations.
Note To create the DLL, you can use the Application Wizard from Visual C++, for
example (MFC-AppWizard (dll)). All functions to be used are entered in this DLL
and are declared as external "C." In addition, each function must also be entered
in the export table.
FAQ solution FAQ 830 1801 Question: How can I implement a self-made DLL in WinCC in the
correct way?
Procedures
(Function)
SITRAIN
ST-BWINCCS /GlobalScript Page 7 Siemens AG © 2007
General Information Global Script is the general term for functions and actions with ANSI-C and VBS.
Use VBS procedures to create a code only once but to make it available at
several points in your project. Instead of entering the code multiple times, you only
have to initiate the corresponding procedure. Your code is more transparent and
easier to maintain.
VBS actions in Global Script are defined one time and are then available
independently of the picture. Global Script actions are only valid in the project in
which they were defined.
Project Modules All project-specific procedures are grouped together under this tab. The
procedures are only applicable within the project (ScriptLib Catalog).
Procedure Characteristics
+ You create and modify them.
+ They can be protected against change and viewing through a password.
+ They don’t have a trigger.
+ They are saved in a module.
Standard Modules This is where functions are located that can be used for more than one project.
(ScriptLibStd Catalog).
Actions Actions are available only in the Global Script. This is where actions are defined
that run in the background and are not connected directly with the selected WinCC
object (screen, screen window, graphic object, etc.). For example, the daily
transmission of values into an Excel spreadsheet.
Code Templates Code templates provide the programming person with frequently used instructions,
such as for loops and conditional instructions. You can insert these templates into
your procedure code using drag & drop.
In the project
Module
Procedure A
Procedure B
Procedure C
Instruction a
Action Instruction b
Instruction 1
Instruction 2
Trigger Procedure C
….
Instruction n Procedure D
Procedure E
SITRAIN
ST-BWINCCS /GlobalScript Page 8 Siemens AG © 2007
VBS in WinCC enables you to use procedures, modules and actions for making
your runtime environment dynamic.
Procedures A procedure corresponds to a function in C. You store the code in procedures that
you would like to use in several locations in your configuration. You call the code in
an action or in another procedure by calling the procedure name. In WinCC you
can create procedures with or without a return value. Procedures don’t have a
trigger; the call is always made through an action.
Modules In modules, you group procedures into meaningful units. You create, for example,
modules for procedures that are used in a specific picture or that belong to a
specific topic, such as mathematical auxiliary functions or database access
functions.
Actions Actions are always brought to a start through a trigger; in other words through a
triggering event. You configure actions for properties of graphic objects, for events
that occur in a graphic object, or globally in the project. In actions, you can call
frequently used code in the form of procedures.
.pdl
Call
SITRAIN
ST-BWINCCS /GlobalScript Page 9 Siemens AG © 2007
General Information For frequently occurring applications, you can create a Global Script function.
Then the function is called in a picture object and supplied with operands.
Execution Event
1. Cell: Tag declaration
2. Cell: Through the OutputValue property, read the value of the 1st IO Field.
3. Cell: Through the OutputValue property, read the value of the 2nd IO Field.
4. Cell: Call the function Sum and supply the output field with the return value.