Blog

Getting Started with WinCC OA: Part 4 - Panel Scripting Environments and QuickTest

Getting Started with WinCC OA: Part 4 - Panel Scripting Environments and QuickTest

Welcome back to “Getting Started with WinCC OA”! If you aren’t familiar with the series’ previous topics, it’s recommended that you read the respective installments before proceeding:

In Part 4 of the “Getting Started with WinCC OA,” we’ll look at implementing scripts within panels. This involves investigating script triggers, writing basic scripts, and testing our code.

Events and Their Respective Scripting Environments

At the end of Part 3 in the “Getting Started with WinCC OA” series, the following question was posed: “What are the items on the bottom half of the Property Editor that say ‘ScopeLib’ and ‘Initialize’?”

On the bottom portion of the Property Editor window lives the panel scripting environments. When clicking between the panel, button, and rectangle, you may notice that the list of “Event[s]” changes based on the object selected.

panel events

rectangle events

rectangle events

Each of these events, save the panel’s “ScopeLib,” has the ability to trigger program scripts. Each event’s respective script can be created and accessed by clicking on the event’s “Open Script Editor” button.

opening script editor

OA’s script editors open in windows outside of Gedi:

script editor in gedi

The ScopeLib, unlike other events, is a panel-specific “Event” whose code can be accessed by all other event-based scripts. With that in mind, however, it’s important to note that the ScopeLib is not event-triggered, so any function within ScopeLib must be called by another event’s script.

DMC’s best practices for OA include that most of a panel’s code development should take place in ScopeLib and that event scripts should be utilized only to call ScopeLib functions.

scopelib in winccOA

Panel Scripting

Recall the questions posed at the end of this series’ previous edition: “What if I want to change my object properties during runtime?” and “how do we get those buttons to do things?” Well, we can do those through scripting.

Let’s consider our TestPanel. Just say we want to make the “Turn Green” button turn the rectangle green and the “Turn Red” button turn the rectangle red. Per best practices stated above, when the “clicked” event is triggered for a button, we’ll call a ScopeLib function from the triggered event’s respective script.

NOTE: The next installment of “Getting Started with WinCC OA” will cover scripting syntax. For now, just copy the example code.

  1. Call a function (yet to be created) from the event script
    1. Select the “Turn Green” button
    2. Open the “Clicked” script editor calling event functions
    3. Call a ScopeLib function (yet to be created) and click the “Save and Close” button scopelib functions
      Click here to view the TurnGreenButton script.
  2. Create the called function in ScopeLib
    1. Select the panel’s empty space
    2. Open the ScopeLib script editor scopelib editor
    3. Write the following function called by the “Turn Green” button’s click event. turn green function
      Click here to view the ScopeLib script.
  3. Repeat step 2 for the “Turn Red” button.
    Click here to view the TurnRedButton script.

Your scripts should now all look like this:

full function

Click here to view the TurnGreenButton script.
Click here to view the TurnRedButton script.
Click here to view the ScopeLib script.

Alternatively, instead of viewing each script separately, pressing Ctrl + E will open up all of the selected panel’s scripts in one window.

selected panel of scripts

Testing a Panel

Now that our code is written out, it’s time to test (and possibly then debug) our panel. To do this, click on the window in which the panel lives and select the “Save and Run in QuickTest Module” button on the toolbar.

running the quicktest module

The test panel will appear as a popup separate from the Gedi window. Now go ahead and give the buttons a try! If all was done correctly, each button should turn the rectangle their labeled color.

running the test for green

running the test for red

The Scripts

Below are all of the scripts that I explained in this tutorial:

TurnGreenButton


main(mapping event)
{
  turnGreenButtonClicked();
}

Return to TurnGreenButton Instructions

TurnRedButton

main(mapping event)
{
  turnRedButtonClicked();
}

Return to TurnRedButton Instructions

ScopeLib

//This function is called when "Turn Green" button is clicked
void turnGreenButtonClicked()
{
  //set the "backCol" property of the "rectangle" object to "green"
  setValue("rectangle", "backCol", "green");
}

//This function is called when "Turn Red" button is clicked
void turnRedButtonClicked()
{
  //set the "backCol" property of the "rectangle" object to "red"
  setValue("rectangle", "backCol", "red");
}

Return to ScopeLib Instructions

Now that we have a good understanding of our panel scripting environments, we’re ready to review the basics of OA’s scripting. The next edition of the “Getting Started with WinCC OA” series will take a closer look at the scripting syntax in WinCC OA.

Topics to look forward to in this series: 

Contact DMC to get started on your next WinCC project and learn more about our Siemens SIMATIC WinCC Programming as well as our WinCC Open Architecture Development.

Comments

There are currently no comments, be the first to post one.

Post a comment

Name (required)

Email (required)

CAPTCHA image
Enter the code shown above:

Related Blog Posts