I am writing a script and having trouble getting it to work correctly.
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
#Get Variable tag paths for writing values
TagPath1 = '[default]Colder Products Company/Roseville/BurstTester/Test1Val'
Var1 = system.tag.readBlocking(TagPath1)
TagPath2 = '[default]Colder Products Company/Roseville/BurstTester/Test2Val'
Var2 = system.tag.readBlocking(TagPath2)
programTagPath = '[default]Colder Products Company/Roseville/BurstTester/ProgramNum/Current_Program_Number.value'
Prgrm = system.tag.readBlocking(programTagPath)
# Flip boolean
system.tag.writeBlocking('[default]Colder Products Company/Roseville/BurstTester/Results/Get_Results_Trigger', 0)
#Write based off Program Number
if Prgrm == '3':
# Write variable value to another tag for linked test (Test 3)
if currentValue.value != 0 and currentValue.value < 3 and currentValue.value != Var2:
system.tag.writeBlocking('[default]Colder Products Company/Roseville/BurstTester/Test1Val', currentValue.value)
elif currentValue.value != 0 and currentValue.value != Var1:
system.tag.writeBlocking('[default]Colder Products Company/Roseville/BurstTester/Test2Val', currentValue.value)
elif Prgrm == '2' and currentValue.value != 0:
system.tag.writeBlocking('[default]Colder Products Company/Roseville/BurstTester/Test1Val', currentValue.value)
elif Prgrm == '1' and currentValue.value != 0:
system.tag.writeBlocking('[default]Colder Products Company/Roseville/BurstTester/Test2Val', currentValue.value)
I was able to get it to work when it looked like this:
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
#Get Variable tag paths for writing values
TagPath1 = '[default]Colder Products Company/Roseville/BurstTester/Test1Val'
Var1 = system.tag.readBlocking(TagPath1)
TagPath2 = '[default]Colder Products Company/Roseville/BurstTester/Test2Val'
Var2 = system.tag.readBlocking(TagPath2)
programTagPath = '[default]Colder Products Company/Roseville/BurstTester/ProgramNum/Current_Program_Number.value'
Prgrm = system.tag.readBlocking(programTagPath)
# Flip boolean
system.tag.writeBlocking('[default]Colder Products Company/Roseville/BurstTester/Results/Get_Results_Trigger', 0)
# Write variable value to another tag for linked test (Test 3)
if currentValue.value != 0 and currentValue.value < 3 and currentValue.value != Var2:
system.tag.writeBlocking('[default]Colder Products Company/Roseville/BurstTester/Test1Val', currentValue.value)
elif currentValue.value != 0 and currentValue.value != Var1:
system.tag.writeBlocking('[default]Colder Products Company/Roseville/BurstTester/Test2Val', currentValue.value)
But as soon as I add the if statement to check on a tag value, it does not seem to work. I checked to make sure that the script was able to read from the tag, and it was able to correctly:
readBlocking returns a list of qualified values, regardless of whether you feed it a list of tag paths or not.
Your expression: if Prgrm == '3':
should be: if Prgrm[0].value == '3':
As for what @Transistor is saying, you should be doing one call to read your tags: