How to make a counter for Ignition Designer using Python

I'm trying to do a counter that would count the amout of times when a tag (measuring conditions) is either 0 or 32767. The counter should count +1 in either case.

I'm trying something like this (but I know it's a mess):

def count(self):

while x == 0 or X == 32676 print count += 1

or somethin like this:

def isEqual(num):

x == 0 or x == 32676
print counter += 1
elif: print counter

2 Answers

You could make a memory tag to store your counter. Then make a gateway tag change script to check for your two values each time the tag changes. Increment your counter each time the tag is equal to either of those two values. Like this:

if (newValue.value in [0, 32676]) and (not initialChange): system.tag.write('counter', system.tag.read('counter').getValue() + 1)
2
  1. set label bound to the tag you are tracking,

  2. create memory tag for counter

  3. add value change script that will run every time the value of the tag you are tracking changes Script should look like:

    counter = system.tag.readBlocking(["[default]My/Tag/counter"])

    counter = counter + 1

    system.tag.writeBlocking(["[default]My/Tag/counter"],["counter"])

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like