I am on an Edge Panel.
We have some tag change script on just regular memory tags. These work perfectly.
We had a UDT instance with a tag change on one of the tags within the UDT that never seems to work.
I am sure I am missing something dumb, but I can't for the life of me figure out WHY just on the UDT instance it doesn't work.
Show your whole script. Also, look in your logs for errors from this script.
(Using import in event scripts is a really bad practice. Do that in project library scripts where you really need it. And don't import from system.*
at all.)
I ran a test one with JUST a logger.
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
from system.tag import readBlocking as read, writeBlocking as write
logger = system.util.getLogger("TriggerDemo")
logger.info("valueChanged: tagPath={0}, prev={1}, curr={2}, initialChange={3}, missed={4}"
.format(tagPath, previousValue.value, currentValue.value, initialChange, missedEvents))
if initialChange:
logger.info("Skipping initialChange")
else:
try:
if currentValue.value:
logger.info("Trigger is True, building request")
func_code = read(["[.]function_code"])[0].value
logger.info("Read function_code: {0}".format(func_code))
msb = read(["[.]msb_address"])[0].value
logger.info("Read msb_address: {0}".format(msb))
lsb = read(["[.]lsb_address"])[0].value
logger.info("Read lsb_address: {0}".format(lsb))
reg_count = read(["[.]register_count"])[0].value
logger.info("Read register_count: {0}".format(reg_count))
request = "{0} {1} {2} {3}".format(func_code, msb, lsb, reg_count)
logger.info("Formatted request: {0}".format(request))
write(["[~]request_master"], [request])
logger.info("Wrote request_master: {0}".format(request))
else:
logger.info("Trigger is False, skipping")
except Exception as e:
logger.error("Error in TriggerDemo logic: {0}".format(e))
write("[.]trigger_request", False)
there is also 0 logs from any of them
I guess other than a script error, is there any other reasons a tag change script would not function on any tag? UDT or other. It seems weird that only the UDT instances doesn't work.
The only other factor that comes to mind would be long-running tag event scripts blocking the thread pool. Pretty sure that would show up in the gateway's running scripts status page. (In general, Ignition event scripts need to run in single-digit milliseconds, with few exceptions.)
I put in a ticket with Inductive. I don't know what else to do
Have you tried logging a constant string instead of using .format()
?
(You should consider using the .infof()
, .debugf()
, and .tracef()
methods of Ignition loggers instead of jython .format()
--the former are much more efficient, and CPU friendly when a logging level is disabled.)
2 Likes
so .format() is not available in a UDT instance tag change script? This has to be a bug??
It is available, but your syntax is convoluted and may be hiding some other problem.
The standard formatting methods of Ignition loggers will always be faster and more efficient.
Try having your value change event be this one-liner:
system.util.getLogger("TriggerDemo").info("Hello!")
i created test UDT with a tag and a tag change script with literally constant string .info() and a formated .format() or .infof() and none of the formatting would work, but the constant string one did.
Be aware that .infof()
and friends use C-style %
placeholders, not curly braces.
I avoid .format()
like the plague, so someone else will have to help you with that.
Huh. Was not expecting that. So, .format()
cannot work in UDT scripts. TIL.
My experience is that curly braces with text between them will cause the silent failure that I reported. By this report curly braces with numbers in between will cause silent failure also. I'll note that the OP's code uses positional references in the .format() calls that are not actually needed.
This will cause silent failure (as reported):
request = "{0} {1} {2} {3}".format(func_code, msb, lsb, reg_count)
While this does not (I suspect).
request = "{} {} {} {}".format(func_code, msb, lsb, reg_count)
... according to my experience with the issue (bug).
The second example is still causing silent failures for us
I suggest you reduce your code down to one line for testing. Also remember that the issue occurs even for comments (including lines of code that are commented out) so remove all commented lines also. I'll try to verify when I'm at a computer (responding on my phone right now).
I suggest you abandon .format()
entirely everywhere loggers are involved. Really
2 Likes