Try the following:
tank_sel = event.source.parent.tank # 1
tagPath = '[default]Filler_Data/DF2_SOURCE_TANK' # 2
sourceTank = system.tag.readBlocking([tagPath]) # 3
if sourceTank[0].value: # 4
output = 0
else:
output = 2 ** (tank_sel - 1) # 5
system.tag.writeBlocking([tagPath], [output]) # 6
Explanation:
- Original code.
- Readability improvement.
- readBlocking expects a list of tag paths. (It does work with only one value not in a list but it's not documented and could change in a future version.) readBlocking returns a list of all the "qualified values" (value, OPC quality, timestamp).
- Get the value (using
.value
) of the first (and, in this case, only) returned tag. The> 0
can be omitted becauseif
returnsTrue
for any non-zero value. - Your output value for tanks 1, 2, 3, 4 is 1, 2, 4, 8 so use the exponent to set the value in one line.
- As with readBlocking, writeBlocking requires lists of tag paths and values.
I think your basic problem was that you were checking the qualified tag where you needed to check .value
.
See this part of the manual: