Aegolius
Aegolius

Reputation: 11

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

Upvotes: 1

Views: 2280

Answers (2)

Ligma
Ligma

Reputation: 13

  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"])

Upvotes: 0

fourmajor
fourmajor

Reputation: 51

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)

Upvotes: 0

Related Questions