Hello!, I have a gateway event which is triggered from a value change from an OPC tag, this event has a script to validate some functions and then write values on the OPC tags.
Some times the function is not writteen to the tag; I already change the function .write to .writeBlocking, but the result its the same.
Im not sure if someone has the same issue, and what I’m doing wrong,
Note: using the function .writeBlocking the results is always good, and I cant get any logs with a error.
However, I’d suggest instead of building your values to write within the function arguments, to write them into a variable which you pass in. It’ll make your life easier when it comes to diagnosing issues as you’ll know exactly what you’re passing into the functions and if they’re in fact valid. Then put a bunch of print statements to check the values
Boolean tags aren't 0 and 1. They are True and False. You can write 0 or 1 to them as a convenience, but your comparisons are broken. Replace the entire 4-line if-elif block with this:
You check for a boolean tag value being True or False like this:
if currentValue:
system.tag.writeBlocking([tagPath],[False])
else:
system.tag.writeBlocking([tagPath],[True])
However, since all you're wanting to do is invert the current value, then you don't need to "check" the value, just use the not keyword to invert the value.
when expressions are used by control flow statements, the following values are interpreted as false: False, None, numeric zero of all types, and empty strings and containers (including strings, tuples, lists, dictionaries, sets and frozensets). All other values are interpreted as true.
Python uses the singleton objects True and False for the boolean constants, unlike other languages which use true and false as constants.
So you could write: if currentValue == True:
And it would work just fine. But idiomatic Python tells you to drop the == True, because it's not really adding any clarity. You are obviously welcome to write your own code however you want, though