Function Cicode calling not working

Hello All,

I'm using Citect Scada 2018 R1 update 16. We are struggling to have cicode functions working. How do i call a function from a graphical page.

Below is the current function call. Are we missing anything?

  • The way you call the function seems correct, however it's possible that your function contains blocking elements, which are not allowed if you call the function directly from graphics or other foreground tasks.

    Examples of blocking elements are:

    - Reading tags using TagRead() commands
    - Using FOR or WHILE loops
    - Using Sleep() or SleepMS() commands
    - Reading from / writing to disk devices or ODBC data sources
    - Executing functions that communicate with alarm-, trend-, report-, or I/O servers in a blocking (synchronous) way
    - Calling VBA-functions or other blocking cicode functions

  • Try making it simpler: put the cicode as the action on a button click or something rather than as a "Cicode" graphic object (Which will continually call the same code). 
    It's hard to make out what your code is doing, but from the looks of things you're trying to set a bunch of variables based on other conditions... why are you doing this from a graphic? I'd consider rethinking the approach

  • hello Patrick,

    Thanks for the feedback. i was expecting atleast one cicode funtion to work. if the Calling method used possibly  not the best way, what are the alternative i can try on. A simple function as below i believe should have worked.

  • On the question on why we are doing this from the graphic?. we are reading this data via OPC on the SCADA and it reads perfectly. we will like to use this data on other PLCs for other controls.  

  • Hi Willem,

    i have tried  putting the action on a cicode command before and it worked though but was looking at freeing the graphics page from alot of cicode functions.

  • It looks like writing to all these variables is taking too long to be used as foreground code. It will also likely not work if no user is logged in.

    If you only want these variables to be written to if this page is active, then you could use TaskNew() to execute your function like this: TaskNew("Overview", "", 1+8)

    This way your function is executed as a background task. Mode 1 specifies that the task will end when you switch to another page and Mode 8 will make sure your function is only starting when the previous execution has finished.

    If you want these variables to be written to even when the page is not shown, then consider calling the function periodically from an event on the I/O server.

  • Thanks Patrick. i have one of the graphic pages which is an overview of the entire plant fixed and cannot be changed on one of the 4 monitors at all times, which will then make sure the task is executed . So i will try the TaskNew() and see the outcome.

    i will try also the the second option using the Event if it becomes necessary. Thanks for your assistance. 

  • If your intention is to run this continually to just pass data back and forth between tags like a mailbox, then the graphic is definitely the wrong place to do this from.
    There are half a dozen better ways including as a periodic script, continually in a for loop (After tasknew), on-change of the monitorred tags, as a periodic report, linking the tags directly together, etc etc.

  • What is the originating system for the tags you're reading? If it's not another computer, then always prefer to use direct comms between PLCs/controllers/devices down at level 1 and use the SCADA system as a mailbox only as a last resort.