I would like to increment a value every 1s.
Here's the script running on script console.
class tagType:
#sets all initial values for the pid library
def __init__(self):
self.i = 0
from time import sleep
newTag = tagType
newTag.i = 10
while True:
print(newTag.i)
newTag.i = newTag.i + 1
sleep(1)
I placed it in Gateway Events, as timer events & 1,000ms.
The above "print" script is replaced to write to a memory tag.
From the above script, the instance "newTag" is created every time the script is called, I thought when the above script is running in Gateway, the print value will remain at 10 because each time the script runs, the new instance will be created, but the value does increase every one second, "10,11,12,13,14.....".
I am a bit confused about how the gateway run the script. It seems that when the instance "newTag" is generated from the class, it retains the last scanned value when the new scan starts at 1second interval.
Then I tried to use the same script in a now(1000) tag, when the tag value changes every 1 second, It will execute the above script. Under this case, the value "newTag" remain at 10, as what I expected.
Now my question is: why the script result from the gateway 1 second timer event is different from the 1 second tag event?
Any comment is appreciated.