Hello,
So i'm trying to increment a numeric value , for each time a tag switches from 1 -> 0 , i should increment my numeric value. I tried this in scripting withing the tag editor but nothing changes in my numeric value
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
if not initialChange:
# Détection d’un front descendant : passage de 1 à 0 (arrêt du convoyeur)
if previousValue.value == 1 and currentValue.value == 0:
# Lire la valeur actuelle du compteur
compteur = system.tag.readBlocking(["[default]Valeur"])[0].value
# Incrémenter le compteur
system.tag.writeBlocking(["[default]Valeur"], [compteur + 1])
I think you should perform the math before the writeBlocking call, and just use the variable in the call. Something like:
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
if not initialChange:
# Détection d’un front descendant : passage de 1 à 0 (arrêt du convoyeur)
if previousValue.value == 1 and currentValue.value == 0:
# Lire la valeur actuelle du compteur
compteur = system.tag.readBlocking(["[default]Valeur"])[0].value + 1
# Incrémenter le compteur
system.tag.writeBlocking(["[default]Valeur"], compteur)
Or maybe a separate line after you get the initial value for compteur like
...
compteur = system.tag.readBlocking(["[default]Valeur"])[0].value
compteur = compteur + 1
...