Applies To:
  • CitectSCADA 1.00, 1.01, 1.10, 1.11, 2.00, 2.01

I have created three Cicode tasks with TaskNew(). These tasks run in the background all the time. What is the priority given to each of the Cicode tasks. 

All Cicode tasks running in the background have the same priority. Citect will schedule all background tasks in a round robin scheduling method, for example task1, task2, task3, task1, task2, task3, etc. Each task will run until it calls a blocking function, or it runs out of its allocated time slice. The time slice is controlled by the parameter [code] TimeSlice and defaults to 100 ms. If all the Cicode tasks don't call any blocking functions, they will each run for 100ms. Between the running of each Cicode task, Citect will run any tasks it needs to execute, for example, foreground Cicode, alarms, trends, I/O Server and various other internal tasks (reports run as background Cicode). If you have 3 tasks, you cannot be sure that each task will run every 300ms, as Citect will execute other tasks between them.

When a Cicode task is started from a keyboard command, report, or TaskNew, that task will start running immediately (assuming it does not have to wait for PLC data, see Q1075). This gives new tasks a boost in priority when they are first started, and provides faster response for keyboard commands. If the task continues to run after its time slice, it will then drop into the normal round robin scheduling, and so have the same priority as all the other running Cicode tasks.

All foreground Cicode tasks run at the same priority, but at a higher priority than all background Cicode tasks. Foreground Cicode includes all Cicode used to display animation on the screen (Numbers, Bars, Strings, Text, Keyboard, Trends etc) as well as events and callback Cicode. Citect will run all pending Foreground Cicode tasks between the time slice of the background Cicode. Citect runs each foreground task until it completes its job or is aborted. For example, if you have 3 background tasks running, and the current page has 5 Cicode animation records, and it takes 1000 ms to read the data for the page from the PLC, and Citect runs internal tasks for 100ms between the background Cicode, the following scheduling will occur:


Note that all the pending foreground tasks run to completion between the background tasks. Also the rate at which foreground tasks run is normally only limited by the rate at which the data is read from the PLC. In the above example, if the PLC data was read in 500ms the foreground tasks would run twice as often. The foreground tasks normally execute very quickly as they are very short tasks, so they will not steal too much CPU time from the background Cicode.

Citect runs foreground tasks to completion, so if you write a piece of foreground Cicode that contains a loop, ie it would try to run forever, Citect will abort the Cicode after 500ms. This time is controlled by the parameter [code] TimeSlicePage. If Citect aborts the Cicode, you will get the hardware error 'Foreground Cicode run too long'. You may get this error if your code is complex and takes longer than 500ms to execute. If this happens, increase the TimeSlicePage option.