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

Summary:
Question: If I have a report that calls a function and that function needs data from the PLC, when is the data read from the PLC? 

Solution:
Citect will read the data required for any functions called in a report before the report starts running. Citect reads the data so that when the report starts executing, it won't have to wait for the PLC data before calling any function. This causes all the waiting for PLC data to occur once before the report starts running, and provides the most efficient reading of the PLC data. Once the report starts running, it will execute very quickly - without waiting for any slow PLC reads. This may cause some side effects as some of the functions may be called conditionally, and so their PLC data is not required. In this case, unnecessary PLC reads will occur, however it has been found under most conditions that it is more efficient to read all the data first. For example the following Cicode can cause unnecessary reads:

IF PLC_VAR = 1 THEN
   MyCicodeFunction();
END

If the PLC_VAR = 1 then the function will be called, if it is not 1 then the function will not be called. However any data that the function may have used is still read before the report starts running.

To summarise, before Citect starts a report or any Cicode task (including keyboard commands), or TaskNew(mode=4), it will build a tree of all possible function calls. As Citect cannot know exactly which functions will be called without executing the Cicode, it will then request the data for all these functions. When the data has been returned, Citect will start to execute the Cicode. This also occurs when you call the ReRead() function.

It is possible for you to optimise this behaviour if required. I would only suggest you to this if the function you are calling requires a very large amount of PLC data. If you call a function using TaskNew(), Citect will not read the data associated with it. This is why there is a special mode in task new to request the PLC data. For example in a report or Cicode you could do the following:

IF PLC_VAR = 1 THEN
   TaskNew("MyCicodeFunction", "", 4);
END

The PLC data associated with MyCicodeFunction will not be read when the report starts - only if and when the TaskNew function is called. Note however that this will create an extra Cicode task that will run in parallel with the report, and the function will not start running until the PLC data has been returned. The report will continue to run.

See also Q1075 for details on how Citect reads from a PLC. 


Keywords:
 

Attachments