Applies To:
  • CitectSCADA 1.00 1.01 1.10 1.11 1.20 2.00 2.01 3.00 4.00

Summary:
Question: What exactly does Citect Define as "Stale Data" ? What does the ReRead() function means by stale data. 

Solution:
Stale data is data which may be out of date from the PLC. Citect tries to keep all data from the PLC as fresh as possible, while at the same time not reading any extra data. This maximises the performance by reducing the total amount of data read from the PLC. Citect always keeps the data fresh for data displayed on graphic pages, trends and alarms. Citect can do this because it has full control on how the data is used. For example the data is either displayed on the screen, saved to the trend files or scanned for alarms. Data can however can become stale is a few unusual cases. This can be in very long executing reports, cicode, keyboard commands and events.

When Citect starts a report or cicode task etc, Citect will first read from the PLC all data it needs to complete a required task. Once the data is read from the PLC the task is executed as fast as possible with the current PLC data. While the task is running Citect will not refresh the PLC data from the PLC. This is not a problem most of the time as most reports, cicode, keyboard commands and events will execute in less than 1 second. Also it is better that the data is not updated as the task will see a snapshot of the data. If for example Citect updated the data while a report way half way through is evaluation the report may produce weird results as the value of a tag at the top of the report may be different at the bottom of the report. The disadvantage of this method is that it is quit valid to write reports and cicode which take a very long time to execute (minutes, hours or days). In fact you can write reports and cicode which never finish executing.

With the above method Citect uses to read the PLC the data the report has access to will become stale after a few seconds. A typical example of a cicode task being effected by stale data is show below:

WHILE TRUE DO
   IF PLC_TAG = TRUE THEN
   ....
   END
END

This code is running for ever checking if the value of a PLC_TAG becomes true. When Citect starts this task it will read the value of PLC_TAG and then execute the cicode. The cicode will execute forever and when the value of PLC_TAG changes in the PLC, this code will not see it change. So the value of PLC_TAG has become stale. To fix this problem you can call the function ReRead() as shown below:

WHILE TRUE DO
   IF PLC_TAG = TRUE THEN
   ....
   END
   ReRead(0);
END

Now when you call ReRead() Citect will read the data associated with this cicode task from the PLC. So when the value PLC_TAG updates in the PLC this cicode task will see the change.

The ReRead() function has two modes of operation. You should normally use mode 0 as this makes you cicode run faster and puts less load on the I/O server. With the above example lets assume that it takes 1ms for the cicode to execute the around the loop and call the ReRead() function. When you call ReRead with mode 0, ReRead will check how stale the data is and if the data is fresh it will not read the data from the PLC but just return. This will take less than 1ms to execute. So the while loop will go around again in 1ms and call ReRead(). Eventually after 3 seconds (the time is adjusted by the parameter [Code]TimeData=3000) the data will become stale. This time ReRead() will request the value of PLC_TAG from the I/O server and will put the cicode thread into a wait state. When the value of the PLC_TAG comes back from the I/O server the ReRead() function will remember the time (so it knows when the data will be stale again) and then return. As the data must be read from the PLC this operation may take from 20ms up to a few seconds depending on how fast the PLC is and how busy the I/O server is. So while the I/O server is reading the data the cicode will stop executing. So you will get the effect of the cicode running very fast around the while loop for 3 seconds then wait for the value of PLC_TAG and then start running again.

If you call ReRead(1) with mode 1, then ReRead() will read the data even if it is not stale. So every time through the loop the cicode task will wait for fresh data from the I/O server. So if the data took 500ms to be returned from the I/O server the while loop will execute twice every second. So now the loop will have the freshes data, but will run slower. It is up to you to select the mode you want depending on what you require.

For a full description of how Citect reads data from the PLC see the KB article Q1075.

The description of how Citect reads data from the PLC is as at version 3.2 and 4.10. This may change in the future and you should check your documentation for the latest information.

 

Keywords:
 

Attachments