What is Global C script in wincc programming and how to use Global C script
Published on May 29, 2025 | Category: wincc
in c programming a function is a block of reusable code that performs a specific task. Instead of writing the same code multiple times, you define it once as a function and call it wherever needed. in wincc scada you can create these global function to use multiple time. in this article we learn how to create and use global scripts in C for Siemens WinCC SCADA systems. This guide covers the structure, syntax, and examples of using C functions in global scripting to build efficient automation logic.
Why Use Functions?
Functions allow you to write a block of logic once and reuse it multiple times throughout your program.following are benifits to use a function in wincc scada c programming
- function are break code into manageable pieces.
- function are use multiple time in a program anywhere.
- simple to test function and it's structure
- function makes code easier to understand
what is function in global script and syntax of function
function is a self-contained block of code that performs a specific task. It is typically designed to take some input (called parameters), process it, and then return a result. If no result needs to be returned, a function can be declared with a void return type.
basic syntax of function in wincc scada c programming
return_type function_name(parameter_list) {
// function body
return value; // if needed
}
- return_type: Specifies the data type of the value that the function will return for example int, float,double. void is if no value is returned.
- function_name: The unique name used to identify the function. It should be meaningful and follow naming rules.
- parameter_list: A list of input variables (also called arguments) that the function can accept. Each parameter has a type and a name. If no parameters, use void
- function body: The block of code inside curly braces { } that defines what the function does. This is where all the operations and logic are written.
- return statement: This sends a value back to the place where the function was called. It is required only if the return_type is not void.
how to create a function in wincc scada global c script
a global script editor are used to make a global function in wincc scada c programming. to open global c script editor in your wincc explorer select global script and than select c script and double click.
create a global function in wincc scada c script
a global script editor is open. now we make a simple global project function and use this function in our screen object and component. select project function and than add new function
create a global function in wincc scada c programming
now automatic function are added. you can remove or change this function to make your own. a basic syntax of a function alredy discussed above. now create a following function and than compile.
- Function Name:
addvalue
– This is the name of the function. It performs the operation of adding three numbers.
- Return Type: – The function returns a value of type double (a floating-point number with double precision).
- Parameters:
- double a – The first input value.
- double b – The second input value.
- double c – The third input value.
- Function Body: Contains the logic to compute the sum of a,b and c.
- Return Statement: return a + b + c; – The result of the addition is returned as a double value to the function caller.
how to use a global function in wincc scada
now open graphics designer and add three input output field and a button. in input output field set tag input1, input2, and input3. select button and add a c action on a mouse click event. add a another input output field to show result of addition, and tag output.
add c script in c action editor
c action editor open here simple double click on project function and selct your function. in out function name is addvalue. double click on it and than add tag or constant value in function assigning parameter popup window.
When a user clicks on a specific object in the WinCC interface, this function reads three input tag values, sums them using a custom function, and writes the result back to an output tag—automating data processing within the SCADA system.
wincc scada c code explanation
- #include "apdefap.h": This line includes the WinCC automation library header which contains predefined functions like GetTagDouble and SetTagDouble for tag access.
- Function: OnClick
- This is a callback function triggered when an object (e.g., a button or graphic) is clicked in the WinCC runtime.
- It receives three parameters: pointers to strings representing the picture name, object name, and property name, which can be used inside the function if needed.
- GetTagDouble("input1"):
- Reads the current double-precision floating-point value from the WinCC tag named "input1".
- The returned value is stored in the variable value1.
- GetTagDouble("input2") and GetTagDouble("input3"):
- Similarly, these retrieve the double values from tags "input2" and "input3" and store them in value2 and value3.
- Calling addvalue(value1, value2, value3):
- This calls a user-defined function addvalue (as previously discussed), which adds the three double values.
- The sum is stored in the variable result.
- SetTagDouble("output", result):
- Writes the computed result back to a WinCC tag named "output".
- The return type of this function is BOOL, indicating success (TRUE) or failure (FALSE), though it is not used here.
Kennethanili
June 17, 2025, 3:30 pmhttps://www.goodreads.com/user/show/191174935-perez-kaden
ThomasTig
June 8, 2025, 6:22 pmhttps://www.prolink-directory.com/Rent-a-car-in-Protugal_342336.html