Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AVEVA™ Plant SCADA

Performing Advanced Tasks

  • Last UpdatedJul 18, 2023
  • 5 minute read

This section introduces and explains event handling, Plant SCADA tasks, Plant SCADA threads, how Plant SCADA executes, and multitasking - including foreground and background tasks, controlling tasks, and pre-emptive multitasking.

Handling Events

Cicode supports event handling. You can define a function that is called only when a particular event occurs. Event handling reduces the overhead that is required when event trapping is executed by using a loop. The following example illustrates the use of the OnEvent() function:

INT
FUNCTION MouseCallback()
INT x, y;
DspGetMouse(x,y);
Prompt("Mouse at "+x:####+","+y:####);
RETURN 0;
END
OnEvent(0,MouseCallback);

The function MouseCallBack is called when the mouse is moved - there is no need to poll the mouse to check if it has moved. Plant SCADA watches for an event with the OnEvent() function.

Because these functions are called each time the event occurs, you should avoid complex or time consuming statements within the function. If the function is executing when another call is made, the function can be blocked, and some valuable information may be lost. If you do wish to write complex event handling functions, you should use the queue handling functions provided with Cicode.

How Plant SCADA Executes

Your multi-tasking operating system gives Plant SCADA access to the CPU through threads. However, this access time is not continuous, as Plant SCADA needs to share the CPU with other applications and services.

Note: Be careful when running other applications at the same time as Plant SCADA. Some applications place high demands on the CPU and reduce the execution speed of Plant SCADA.

The Plant SCADA process has many operations to perform, including I/O processing, alarm processing, display management, and Cicode execution - operations that are performed continuously. And, because Plant SCADA is a real-time system, it needs to perform the necessary tasks within a minimum time - at the expense of others. For this reason, Plant SCADA is designed to be multitasking, so it can efficiently manage it's own tasks.

Plant SCADA performs its tasks in a specific order in a continuous loop (cycle). Plant SCADA's internal tasks are scheduled at a higher priority than that of Cicode and have access to the CPU before the Cicode. For example, the Alarms, Trends, and I/O Server tasks all get the CPU before any of your Cicode tasks. The reports are scheduled at the same priority as your Cicode. Plant SCADA background spoolers and other idle tasks are lower priority than your Cicode.

For Cicode, which consists of many tasks, Plant SCADA uses round-robin single priority scheduling. With this type of scheduling each task has the same priority. When two or more Cicode tasks exist, they each get a CPU turn in sequence. This is a simple method of CPU scheduling.

Note: If a Cicode task takes longer than its designated CPU time to execute, it is preempted until the next cycle - continuing from where it left off.

Multitasking

Multitasking is when you can run more than one task at the same time. Windows supports this feature at the application level. For example you can run MS-Word and MS-Excel at the same time.

Plant SCADA also supports multitasking internally; that is you can tell Plant SCADA to do something, and before Plant SCADA has completed that task you can tell Plant SCADA to start some other task. Plant SCADA will perform both tasks at the same time. Plant SCADA automatically creates the tasks, leaving you to call the functions.

Multitasking is a feature of Plant SCADA not the operating system. Many applications cannot do this, for example if you start a macro in Excel, while that macro is running you cannot do any other operation in Excel until that macro completes.

A multitasking environment is useful when designing your Cicode. It allows you to be flexible, allowing the operator to perform one action, while another is already taking place. For example, you can use Cicode to display two different input forms at the same time, while allowing the operator to continue using the screen in the background.

Foreground and Background Tasks

Cicode tasks (or threads) can be executing in either foreground or background mode. A foreground task is one that displays and controls animations on your graphics pages. Any expression (not a command) entered in a property field (that is Text, Rectangle, Button, etc.) is executed as a foreground task. Any other commands and expressions are executed in background mode.

The difference between a background and foreground task is that a background task can be pre-empted. That is, if system resources are limited, the task (for example, the printing of a report) can pause to allow a higher priority task to be executed. When the task is completed (or when system resources become available) the original task resumes. Foreground tasks are the highest priority and can not be pre-empted.

Controlling Tasks

You can use the Task functions to control the execution of Cicode tasks, and use the Plant SCADA Kernel at runtime to monitor the tasks that are executing. Since Plant SCADA automatically creates new tasks (whenever you call a keyboard command, etc.), schedules them, and destroys them when they are finished, users rarely need to consider these activities in detail.

Sometimes it is desirable to manually 'spawn' a new task. For example, suppose your Cicode is polling an I/O Device (an operation which need to be continuous), but a situation arises that requires operator input. To display a form would temporarily halt the polling. Instead you can spawn a new task to get the operator input, while the original task continues polling the device.

Note: The TaskNew Cicode function is used to spawn new tasks.

Pre-emptive Multitasking

Cicode supports pre-empted multitasking. If a Cicode task is running, and a higher priority task is scheduled, Plant SCADA will suspend the original task, complete the higher priority task and return to the original task.

Preemption is supported between Cicode threads and other internal processes performed by Plant SCADA. You can, therefore, write Cicode that runs forever (for example, a continuous while loop) without halting other Cicode threads or Plant SCADA itself. For example:

INT FUNCTION MyLoopFunction()
WHILE TRUE DO
// Whatever is required in the continuous loop
Sleep(1); // Optional
END
END

In the above example, the function Sleep() is used to force preemption. The Sleep() function is optional, however it will reduce the load on the CPU, because the loop is suspended each second (it will not repeat at a high rate).

In This Topic
Related Links
TitleResults for “How to create a CRG?”Also Available in