Scheduled Cicode

Hi;

I want a function in Cicode to run continuously for a time period that I set. For example, the code I wrote will run every 20sec in the background . How do I make this application?

I am using Power Scada Operation to develop my project.

The function will be as follows;

/////////////////////////////////////////////////////////////
FUNCTION
Schedule()
INT nIntTagValue;
WHILE 1 DO
nIntTagValue = TagRead("VALUE");
nIntTagValue = (nIntTagValue/2) * 3;
TagWrite("VALUE_CALC", nIntTagValue);
END
END
/////////////////////////////////////////////////////////////

Thank you for your reply.

  • Firstly, you can't use blocking code in background tasks, for example, TagWrite is a blocking function (the help will tell you if a function is blocking). You'll need to replace that with simply Value_calc = value. TagRead is blocking as well in certain modes.

    To schedule cicode, you can use either an event or a report. You can configure an event to run on servers or clients, but an event will run anywhere it's configured to run, and won't care about redundancy. In order to configure a redundant task that will run only on the primary in a redundant system, and run on the stnabdy only if there s no access to the primary, then you should setup a report. The report file should contain the cicode to run.
    Eg
    {CICODE}
    Schedule()
    {END}

    Read up in the help about the report file format for more details
  • Hi Yusuf,
    Another option, which will require a lot less code and configuration, and more flexibiltiy, is to use the scheduler feature. Check out the example project, which contains a simple example of the schedule turning lights on and off. More info on this feature in the help too: https://gcsresource.aveva.com/Citect/WebHelp/citect2018/Content/Scheduler.htm?Highlight=schedule
  • Firstly; thanks all for replies.

    My function is working every 20 sec now as my expectation. I have changed my project by following Nick's reply. I added an event with period=20 sec, action=myfunc(), name=GLOBAL configuration and also I set [Event]InhibitEvent = 0, [Event]Server =1 at citect.ini.

    Just I didn't understand a point about event name. If I change the event name "GLOBAL", the event is not working.
    Why the name should be "GLOBAL" and not somethingelse?
  • If you enable events on your computer ([Event]Server=1), any events named global will automatically run in the client process. If you want other event names to run, then you need to run the Setup Wizard and choose which events will run in which process. Also, event names are actually group names, so you can give multiple events the same name. I recommend you name them according to the computer/process where they need to run like Client, AlarmServers, PrimaryTrend, IOServer_P, etc.