1

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 2

0

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
  • Thank you. I had a thought of that, but my execution was not as sophisticated. I still did not get it to work. I did a memory tag to my SQL tags, and then I made a script to Project Browser to Event Scripts (Gateway). I copied your skript to there and added the SQL tag that would trigger the counter. But still...
    – Aegolius
    Commented Aug 9, 2017 at 7:54
  • I wanted to test it so I changed the [0, 32676] for example to [235] to see if it counts (so that when the value would change to 235 it would count +1), but it did not. Did I do a mistake?
    – Aegolius
    Commented Aug 9, 2017 at 8:02
0
  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"])

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.