Hi! Trying to move my scripts from tag event changes to gateway timer events and have the following error: "line 18, in
AttributeError: 'NoneType' object has no attribute 'strip'"
Line 18 is the "mode = ATFTk[i].value.strip().upper()"
However, when I run the tag value change script, it works fine. Why would the tag event change script work, but the gateway event not?
ATFLOCAPLines = [ #List of connectiosn from locap to atf
"[~]ATF Pipeline Lineups/LOCAP TK1501",
"[~]ATF Pipeline Lineups/LOCAP TK1502",
"[~]ATF Pipeline Lineups/LOCAP TK1503",
"[~]ATF Pipeline Lineups/LOCAP TK1504",
"[~]ATF Pipeline Lineups/LOCAP TK1505",
"[~]ATF Pipeline Lineups/LOCAP TK1506",
"[~]ATF Pipeline Lineups/LOCAP TK1520",
"[~]ATF Pipeline Lineups/LOCAP TK1523",
"[~]ATF Pipeline Lineups/LOCAP TK1525"
]
MassBalance = 0
fiveflow = system.tag.read("[~]Pipeline Flows/5 Meter Flowrate LOCAP").value
sixflow = system.tag.read("[~]Pipeline Flows/6 Meter Flowrate LOCAP").value
ATFTk = system.tag.readBlocking(ATFLOCAPLines)
for i in range(len(ATFLOCAPLines)):
mode = ATFTk[i].value.strip().upper()
name = ATFLOCAPLines[i]
split = name.split()
fixedname = split[-1]
if mode == "OPEN": # If Pipeline is going on that route to tank
MassBalance += fiveflow + sixflow # If flow is going to ATF tanks, add LOCAP Pipeline Flows
print(MassBalance)
system.tag.write("[.]../LOCAP/Pipeline Detection/Pipeline Connected.value", "LOCAP")
system.tag.write("[.]../LOCAP/Pipeline Detection/ATF Tank Connected to Pipeline.value",fixedname)
system.tag.write("[.]../LOCAP/Pipeline Detection/Mass Balance After Pipeline Detection.value",MassBalance)
break
else:
system.tag.write("[.]../LOCAP/Pipeline Connected.value", "NO LOCAP PIPELINE CONNECTIONS DETECTED, USE INDIVIDUAL TANK MASS BALANCES FOR VERIFICATION")
You base issue is that your tag provider is not explicitly provided in your tag paths, note the ~ and . in the square brackets. This works in client scope because it knows what the default provider is. If it's in gateway scope, it doesn't know what provider to use, so you need to change your tag paths to be fully qualified.
Because of this your tag read is returning null values which don't have the .strip() method, because they have no value.
On to the script, you're tanking your performance in this script, that it was in tag value change event is worrisome at best.
You should do a single read at the beginning of the script, and a single write at the end of the script. The writes here aren't so bad because they are using the deprecated system.tag.write() which just happened to be asynchronous. But the reads are all blocking and that's a bad thing in value change scripts. So there are some improvements that you can make to the script:
ATFLOCAPLines = [ #List of connectiosn from locap to atf
"[~]ATF Pipeline Lineups/LOCAP TK1501",
"[~]ATF Pipeline Lineups/LOCAP TK1502",
"[~]ATF Pipeline Lineups/LOCAP TK1503",
"[~]ATF Pipeline Lineups/LOCAP TK1504",
"[~]ATF Pipeline Lineups/LOCAP TK1505",
"[~]ATF Pipeline Lineups/LOCAP TK1506",
"[~]ATF Pipeline Lineups/LOCAP TK1520",
"[~]ATF Pipeline Lineups/LOCAP TK1523",
"[~]ATF Pipeline Lineups/LOCAP TK1525",
"[~]Pipeline Flows/5 Meter Flowrate LOCAP",
"[~]Pipeline Flows/6 Meter Flowrate LOCAP"
]
tagValues = [qv.value for qv in system.tag.readBlocking(ATFLOCAPLines)]
fiveflow, sixflow = tagValues[-2:]
ATFTk = ""
name = ""
for i,val in enumerate(tagValues[:-2]):
if val.strip().upper() == "OPEN":
ATFTk = val
name = ATFLOCAPLines[i].split()[-1]
break
tagPaths = ["[.]../LOCAP/Pipeline Detection/Pipeline Connected",
"[.]../LOCAP/Pipeline Detection/ATF Tank Connected to Pipeline",
"[.]../LOCAP/Pipeline Detection/Mass Balance After Pipeline Detection"]
connected = "LOCAP" if ATFTk else "NO LOCAP PIPELINE CONNECTIONS DETECTED, USE INDIVIDUAL TANK MASS BALANCES FOR VERIFICATION"
writeValues = [connected,name,fiveflow + sixflow]
system.tag.writeAsync(tagPaths, writeValues)
You'll need to replace the relative tag paths with the fully qualified ones that are needed, but otherwise this script should be much more performant (also more readable imho).