Need help checking if a tag has a null value

I’m having some trouble figuring out a code for checking if a tag has a null value.

I have a string coming from the plc that changes between having 5 digits and 10 digits, (either 2 different part numbers or 1 part number) depending on what fixture is put in the machine. I have split the part numbers into 2 separate tags. When the string only has 5 digits, one tag is null.

I want to check if this tag is null, and write a value to a third tag ‘Bin 11-2’ depending on if it is or isn’t.

I’ve tried using IsNull and == None, but it’s not working… Am I missing something?

This is the code I have now (a tag event script) :
Any help would be appreciated!!

image

None is special in python. It is never equal to anything else. You must use the is operator. Like so:

if system.tag.read("some/tag/path").value is None:
   # do something

Note that IsNull() is a SQL thing, not python.

2 Likes

Thank you very much! Everything works now. Appreciate the help. And I didn’t know IsNull wasn’t a python thing… so thanks for that too.

I am having the same problem.
In value change I have to check to see if that value is null:

This is the script:

CrValue=currentValue.value
if CrValue is None:
   print "ok"

I do not see anything in the console.

Tagevents scripts don’t print on the console because they are gateway scope. they print on the wrapper log file

this is from the manual.

https://docs.inductiveautomation.com/display/DOC80/Tag+Event+Scripts

you could print by clicking a button from the tagevent and print “ok” from there , and it will then print in the console.

1 Like

Thank you! Appreciate the info. I do not see anything in the log as well. So it means the script is incorrect? I do not get any errors too.

what version are you using? and can you post the full script?

1 Like

I am using version 8.1.10
I have a query tag and in its value change script I have the code below:

if previousValue != currentValue.value:
    CrValue=currentValue.value
    if CrValue is None:
             print "ok"

add a print statement before each step and you will know where you are getting stuck.
also your query tag what value does it show in the tag browser when you get the null value from the query? you need to make sure that you compare correctly the value you are getting.

you can put this on client scope script, tag event. and it will print on the client console

print 1
if previousValue != currentValue.value:
CrValue=currentValue.value
print 2
if CrValue is None:
         print "ok"
1 Like

Alternatively you can configure a logger using system.util.getLogger to log to the gateway logs.

1 Like