Would greatly appreciate your kind advises or assistance for this peculiar issue with memory tag that I have had experience and had been cracking my head and also searching and reading the forum or manuals for few days but still could not find any solution. There wasnt any error message though but just that the memory tag isnt showing the correct value after executing the script.
I tried to put in a while loop to check certain condition and to read from another memory tag and upon checking, perform a mathematical operation and then write to this memory tag. However, it was discovered that on the very first time after i started my computer , it works but subsequently, it didnt works. Similarly if i restart my pc again, for the first time, it work but after that when i run it again, it didnt work any more.
from datetime import datetime import jarray, traceback from java.lang import String, Thread from java.util import Date import time import re import sys import system from decimal import * counter = 0 opm = False status = False current = round(system.tag.read("EM/Opm/Eel").value , 6) W4_input = system.tag.read("EM/Opm/W4").value W4 = round(W4_input, 6) if -0.125 < current < 0.125 : opm = True system.tag.write("EM/Opm/W4",W4) else: while counter <3 and not opm: if -0.125 < current < 0.125 : opm = True break else: W4_input = system.tag.read("EM/Opm/W4").value W4 = round(W4_input, 6) W4_new = W4*0.75 system.tag.write("EM/Opm/W4",W4_new) current = round(system.tag.read("EM/Opm/Eel").value , 6) if -0.125 < current < 0.125 : opm = True system.tag.write("EM/Opm/W4",W4) else: continue counter +=1
The inital value of W4 is 100.
Thus when “current” is not in the defined range, it will go into the while loop for 3 times.
However, at the third time, the memory tag is still 75 instead of 42.1875.
Meaning i loop it 3 times but the value remain at the first time of mathematical execution only.
Wonder what am I missing? Or what has gone wrong?
Would appreciate any advise to correct the error.
Thank you very much