c=currentValue.value
p=previousValue.value
if not initialChange:
if p!=c:
if c==0:
BDindex=system.tag.readAsync("[Malu OPC tags]Rubber_Extruder/BDIndex/BDIndex").value
system.tag.writeAsync("[Malu OPC tags]Rubber_Extruder/BDIndex/BDIndex",BDindex+1)
How to modify the code to make it works, thanks a lot.
@deon.korb is right, writeAsync doesn’t return the value.
You also don’t need to check for previous != current since it’s a value changed script.
if not initialChange and currentValue.value:
idx = system.tag.readBlocking(["[Malu OPC tags]Rubber_Extruder/BDIndex/BDIndex"])[0].value
system.tag.writeAsync(["[Malu OPC tags]Rubber_Extruder/BDIndex/BDIndex"], idx+1)
This is out of order. When initialChange is true, previousValue is null. So the preceding line blows up trying to look up .value on a None. Move the assignment to p to after that check.