On page exit event not working

Hello,

We are attempting to log the any change in variables which someone might change on a page in Citect 2018 R2. We are using a function to do this (if an example is required let me know). The function executes correctly when we enter the page, but for some reason it doesn't log the variables when we exit the page. The reason we are trying to do both is to log the values before and after someone accesses the page. Also, We have migrated the project from Citect 7.3 to Citect 2018 R2. 

Parents
  • I like to add TraceMsg() or ErrLog() commands at the beginning and end of a function (and sometimes in between) so I can see if the function is running at all, getting the expected results, terminating before the end, etc. For example:

    Int Function Blah(INT iVal)
      ErrSet(1);
      ErrLog("Blah(" + iVal:# + ") Started");

      If bConditionX Then
        ErrLog("Blah() Condition X Handled");
      End

      ErrLog("Blah() Finished. Returning " + iReturn:#);
      Return iReturn;
    End

    Make sure to call ErrSet(1); at the beginning of the function so it doesn't get terminated for a fatal error (but you have to check for errors returned from function calls within your code).

    See the custom ErrLogEx() function if you want to leave this logging code in but enable/disable it at any time so you're not filling the logs with unnecessary information.

    I'm not clear exactly how your code works or is supposed to. I hope it's not logging every editable tag value that's on the screen--that seems like a lot of unnecessary logging that could make it hard to find what you actually need, and it could be easy to misconfigure which tags it needs to log. Also, if it is just logging the current values on entry and exit, that doesn't necessarily mean the local user changed the value. It could have been changed by another client (if there is one), by another process, by the PLC, etc. Also, what if the user changes the value then changes it back before leaving the screen? The log would not show any changes. What if the user changes the value but leaves the screen open for hours or days? The log would not indicate the correct time the value changed. What if the runtime is stopped or restarted while the screen is open? Is your code able to reliably read and log the values before shutdown?

    Some customers make a custom ChangeSetpoint function or similar. Then, the graphics must be configured to call your ChangeSetpoint function instead of writing directly to tags. The function needs to read the current tag value, prompt the user for the new value, write the new value to the tag, and log something like "User w changed tag x from y to z".

    Another way to do it without editing every input graphic is to use the tag write event queue. If you enable the write queue, every tag write from the current process gets added to a queue in memory. You write a function to read each timestamp, tagname, and value from the queue and log them. See the TagWriteEventQue() Cicode Function documentation.

    With either the change setpoint function or tag write queue you'd have a record of what was changed by what user. You could also trend those tags so you'd have a record of when the value changed even if the change was outside of Citect.

Reply
  • I like to add TraceMsg() or ErrLog() commands at the beginning and end of a function (and sometimes in between) so I can see if the function is running at all, getting the expected results, terminating before the end, etc. For example:

    Int Function Blah(INT iVal)
      ErrSet(1);
      ErrLog("Blah(" + iVal:# + ") Started");

      If bConditionX Then
        ErrLog("Blah() Condition X Handled");
      End

      ErrLog("Blah() Finished. Returning " + iReturn:#);
      Return iReturn;
    End

    Make sure to call ErrSet(1); at the beginning of the function so it doesn't get terminated for a fatal error (but you have to check for errors returned from function calls within your code).

    See the custom ErrLogEx() function if you want to leave this logging code in but enable/disable it at any time so you're not filling the logs with unnecessary information.

    I'm not clear exactly how your code works or is supposed to. I hope it's not logging every editable tag value that's on the screen--that seems like a lot of unnecessary logging that could make it hard to find what you actually need, and it could be easy to misconfigure which tags it needs to log. Also, if it is just logging the current values on entry and exit, that doesn't necessarily mean the local user changed the value. It could have been changed by another client (if there is one), by another process, by the PLC, etc. Also, what if the user changes the value then changes it back before leaving the screen? The log would not show any changes. What if the user changes the value but leaves the screen open for hours or days? The log would not indicate the correct time the value changed. What if the runtime is stopped or restarted while the screen is open? Is your code able to reliably read and log the values before shutdown?

    Some customers make a custom ChangeSetpoint function or similar. Then, the graphics must be configured to call your ChangeSetpoint function instead of writing directly to tags. The function needs to read the current tag value, prompt the user for the new value, write the new value to the tag, and log something like "User w changed tag x from y to z".

    Another way to do it without editing every input graphic is to use the tag write event queue. If you enable the write queue, every tag write from the current process gets added to a queue in memory. You write a function to read each timestamp, tagname, and value from the queue and log them. See the TagWriteEventQue() Cicode Function documentation.

    With either the change setpoint function or tag write queue you'd have a record of what was changed by what user. You could also trend those tags so you'd have a record of when the value changed even if the change was outside of Citect.

Children
No Data