Calling a cicode function from a page event doesn't work at times

Further to an earlier post about passing a cicode global variable argument into a function that is called by a super genie graphic window, I have got all the code working properly thanks to the wonderful help from this community!

It seems now the problem I have is that the function is not always called when the supergenie window is called. I have created a variable on the supergenie window that tells me if the code has been executed and in some cases it has not.

The variable that is set true by the code, so I then created a 'while do' loop to try and execute the code continuously until the variable is set true.

I think the problem is that for some reason the page event doesn't always run when the page (supergenie) is called and leaves check variable false, indicating the code has not been executed.

I have read all the help documentation and believe everything is correct. The documentation notes that there can be issues when using the 'on page entry' event so I have used 'on page shown event'. I note that the 'while page shown' event does not at work at all and not sure why this is.

Any help appreciated

Regards

Daryl

Parents
  • Patrick and Eric,

    Patrick,

    Thank you for your replies.

    I don’t think its login issue as the project start cicode logins the operators and they are never logged out.

    I did try calling the BlockedTrnSetPen function from the cicode where the TrnSetPen is called however it didn’t work because the TrnSetPen uses a negative AN number because the trendpage is super genie.

    Syntax

    TrnSetPen(nAN, Pen, Tag)

    AN:

    The AN where the trend is located.

    -1 - All trends on the current trend page.

    -2 - The function being called is using the special AN setup by the TrnSelect() function.

    The BlockedTrnSetPen wont work with a negative AN number so AVEVA’s recommendation was to call the function from the trend page so the actual AN number of the trend on that page can be used in BlockedTrnSetPen call arguments.

    Would using TaskNew() not give me the same issue of not being able to use the actual trend AN of the page in the BlockedTrnSetPen arguments?

     

    Eric,

    Apologies for programming ineptness but I’m a control engineer at core and not from a coding background.

    I implemented what I thought you suggested but cicode wont compile.

    Below is what I implemented.

    INT

    //PUBLIC

    FUNCTION

    ErrSet(1);

    TraceMsg("TrendFn started");

    BlockedTrnSetPen(INT hAN, INT nPen, STRING sTrend)

        INT timeout = 5000

        INT myhAN

        INT mynPen

        STRING mysTrend   

        INT sleepTime = 10

        INT error = -1

        INT elapsed = 0

        INT currentTime

        STRING sPenName

        INT ErrorVariable

        INT iTrendPenChkd = 0  

        mysTrend = sTrend

       myhAN = hAN

        mynPen = nPen

        error = TrnSetPen(hAN, nPen, sTrend)

        IF error = 0 THEN

            error = -1

            currentTime = SysTime()

            WHILE error <> 0 AND elapsed < timeout DO

                sPenName = TrnGetPen(hAN, nPen)

                ErrorVariable=IsError()

                IF sPenName = mysTrend THEN

                    error = 0

                    iTrendPenChkd = 1

                    TrendPenChkd = iTrendPenChkd

                ELSE

                    SleepMS(sleepTime)

                    elapsed = elapsed + SysTimeDelta(currentTime)

                END

            END

        END

        RETURN error

    TraceMsg("TrendFn finished");

    END

    Regards

     

    Daryl

  • Change:

    FUNCTION

    ErrSet(1);

    TraceMsg("TrendFn started");

    BlockedTrnSetPen(INT hAN, INT nPen, STRING sTrend)

    to

    FUNCTION

    BlockedTrnSetPen(INT hAN, INT nPen, STRING sTrend)

    ErrSet(1);

    TraceMsg("TrendFn started");

Reply Children