Troubleshooting tag event script suggestions?

I have a situation that I need some assistance with. I’m not much of a coder and I’ve been tasked with troubleshooting a project someone else wrote. We’ve got a UDT for each workstation. On that UDT are tags for some call buttons, Button 1, 2, 3, etc. On those call button tags are tag event scripts triggered by a value change that log, in an SQL table, what button was pressed on what station, at what time, and how long it it was active.

Button 3 is being logged properly at station 1 but not 2 and I’m trying to figure out why.

When Button 3 is pressed at station 1, all the desired information is logged. When Button 3 is pressed at station 2, nothing gets logged although it does for the other two buttons. I can see that the associated tag values are changing so the logging should be triggered.

As it stands right now, there’s no way to see what happens when the script is triggered that I’m aware of. If I’m not seeing it, please point me in the right direction. How can I generate a log so I can see if there’s an error occurring when the tag event script executes? The training videos mention wrapper logs or something similar that you can create but it went over my head.

1 Like

If the tag diagnostics on the tags are not showing any error, then, your best bet is to implement a logger with a try…except structure.

Something like:

import java.lang.Exception
logger = system.util.getLogger("yourLoggerName")

     #script to attempt
except: java.lang.Exception, e:
     logger.warn("An error occurred" , e)
except Exception, e:
     logger.warnf("An error occurred: %s",e)

@pturmel has a PythonAsJavaException class in his which will allow for more detail in the case of python exceptions

Thanks for your reply. I got back to this today. I added your code around the code I’m trying to troubleshoot and tested the buttons. I’m not seeing anything in the logs though. Can I assume that an exception in these circumstances would be something like, say, a DB query looking for a column that doesn’t exist, where SQL would generally throw an error?

If SQL throws and error, it would be caught and printed to the log. If you are not seeing any errors in the log, this means 1 of 2 things.

1.) The code is not being executed. You have already stated that the tag values are changing, and we can be fairly sure that Ignition is raising the value change event. That leaves only the possibility that some conditional code is causing the script which would log any errors to not be executed. Probably a safe bet this isn’t the case.

2.) The code is not throwing any errors. This seems to be the most logical conclusion from what you have posted. This would mean that values in the code are not what you expect them to be. I would recommend using the logger more extensively, much like you would use the print statement for debugging purposes in the console.

The logger has multiple functions for logging various types of information at various levels of severity.

From the manual:

  • Logger.fatal(String) - Logs a message with level fatal.
  • Logger.fatalf(String, Args…) - Logs a formatted message with level fatal,
    using Java’s Formatter syntax.
  • Logger.error(String) - Logs a message with level error.
  • Logger.errorf(String, Args…) - Logs a formatted message with level error, using Java’s Formatter syntax.
  • Logger.warn(String) - Logs a message with level warn.
  • Logger.warnf(String, Args…) - Logs a formatted message with level warn, using Java’s Formatter syntax.
  • - Logs a message with level info.
  • Logger.infof(String, Args…) - Logs a formatted message with level info, using Java’s Formatter syntax.
  • Logger.debug(String) - Logs a message with level debug.
  • Logger.debugf(String, Args…) - Logs a formatted message with level debug, using Java’s Formatter syntax.
  • Logger.trace(String) - Logs a message with level trace.
  • Logger.tracef(String, Args…) - Logs a formatted message with level trace, using Java’s Formatter syntax.
  • Logger.isTraceEnabled() - Returns True if the current log level is at least trace.
  • Logger.isDebugEnabled() - Returns True if the current log level is at least debug.
  • Logger.isInfoEnabled() - Returns True if the current log level is at least info.

I think the issue is the latter you described. It’s executing and the query is just coming up empty. Since the query is attached to a UDT and the same UDT is used across several stations, why we’re getting the results we want on several other stations but not this one is confusing. I’m trying to figure out what’s different about the problem station compared to the others. I appreciate your responses.