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

Summary:
Question: How does Citect read from the PLC? 

Solution:
Citect reads from the PLC all data it needs to complete a required Cicode task, or process before starting that task. For example, when you schedule a report, Citect will read all PLC data that the report may need, and any data a Cicode function (called by the report) may need before the first line of the report starts running.

This may have some side effects you should allow for. Firstly, as Citect must read the PLC when you schedule a report, or start a keyboard command etc, there will be a short delay before the Cicode starts to execute - until the read data (associated with it) is read from the PLC. If there is no data to be read from the PLC, the Cicode or process will execute immediately. For example if you have a keyboard command as follows:

Key Seq: ENTER
Command: Prompt("Value of PLC_Var" + PLC_VAR: ####);
Privilege:
Comment:
Display value of PLC_VAR from the PLC

Citect will first ask the I/O Server to read the value of PLC_VAR from the PLC. It will then do something else while it waits for the PLC to send the data back. When the data is returned, it will start to execute the Cicode. Because of this operation, you may even have time to start another keyboard command before this one completes. This effect could cause problems if the data was displayed at say AN 50 and while waiting for the data you changed pages. Then the value of PLC_VAR would be displayed on the new page!. This is normally not a problem - unless you are doing some complex Cicode operations.

If Citect cannot read the data from the PLC for some reason, eg the PLC is offline or the data is bad, Citect will still start the report, Cicode etc. Citect will generate a Hardware error, however it is up to you to test for errors if it will impact on your Cicode. If you call the function ErrCom(), it will tell you if all the PLC variables associated with your report or Cicode is OK. So you could do the following in a report:

{CICODE}
   IF ErrCom() <> 0 Then
   PrintLn("This Report contains bad data");
   END
{END}

Under some special conditions Citect will not read the PLC before starting a piece of Cicode. This includes callback events, Alarm ON/OFF action and any Cicode task created with TaskNew() without using mode 4. Under these critical conditions, Citect wants to start the Cicode immediately, and as it is a critical operation, Citect will not read the PLC first. If you require PLC data under these conditions, create a new task using TaskNew (mode 4).

If Citect does not read the PLC, or the PLC data is bad, you may want to know what value you will get. The value may be 0, or the last valid value read from the PLC. At startup, all variables are set to 0 and they are only read when they are required. Variables used with Cicode functions start at zero. Once read they retain their value until Citect shutdown. If the PLC goes offline, Cicode functions will see the last value. This is also true for reports, trends and alarms, ie the databases that are always loaded in memory. Display pages are loaded into memory when you go to them, and are removed from memory when you close them. Each time you display a page, all its variables are reset back to 0. If the PLC goes offline, the data on the current page will stay at its current value. If you then go off that page and then come back all variables will be zero.

See also Q1073 for details on how Citect writes from a PLC. 


Keywords:
 

Attachments