Timer script isn't working or showing in gateway

Hello, I'm trying to run a timer script (code found here on ignition) for incrementing a value by 1 but it doesn't work. The tag in question is a memory tag. The value of my tag in tag browser stays on 0 and the script doesn't show in the script gateway. I'm also not getting any errors in my logs. Does anyone know what the problem is?

Count = system.tag.read("Line1Counter")
if Count.value < 30000:
New_Count = Count.value + 1
system.tag.write("Line1Counter",New_Count)
else:
New_Count = 0
system.tag.write("Line1Counter",New_Count)

Please see Wiki - how to post code on this forum. Then use the pencil icon below your question to edit and fix it. Otherwise we don't know if you've got your Python indentation right.

Apologies about that and thank you. I added a screenshot of how it’s formatted in the gateway timer script

Count = system.tag.read("Line1Counter")
if Count.value < 30000:
   New_Count = Count.value + 1
   system.tag.write("Line1Counter",New_Count)

else:
   New_Count = 0
   system.tag.write("Line1Counter",New_Count)

The logs are in the gateway - under Status -> Gateway Scripts -> Timer tab.
I copied your script and got an ERROR in the list, which showed multiple faults - my bad, I miscopied something - your script seems to run fine as it is.

You need to click the Save button in the Designer to get the Gateway to update after every change to the script!

1 Like

Many thanks! I feel so silly. I wasn’t saving the project afterwards.

General comments:

  • system.tag.read() has been depreciated. You should be using system.tag.readBlocking | Ignition User Manual.
  • Similarly system.tag.write() has been replaced with system.tag.writeBlocking | Ignition User Manual.
  • The code you posted doesn't match the screenshot. The posted code has three leading spaces on each indented line. The screen shot shows four on lines 3 and 4 and eight on lines 7 and 8. (Or one tab and two tabs.) This makes it very difficult to know for sure where the errors are.
  • Both readBlocking and writeBlocking expect [ ] lists of tags and values. Code can be written like this (but not tested):
Count = system.tag.readBlocking(["Line1Counter"]).value
if Count < 30000:
   system.tag.writeBlocking(["Line1Counter"], [Count + 1])
else:
   system.tag.writeBlocking(["Line1Counter"], [0])
  • Also, as explained earlier, you can edit posts instead of deleting and reposting.
1 Like

Don't worry about it... I reduced the script down to just writing 10 to the tag before I figured out it wasn't the script itself!

Thank you! I’ll make those changes