Counter Active Tag

Hello, I currently have an opc tag that gives a count of the product. What I'm trying to do is to create another tag that says if the machine is counting or not (a Boolean value) and if the count stops for more than a min the tag shows false.

There are several ways I think you could do this, and I not the most familiar with the expression language, so I was using tag event scripts.

So, on my counter, I have a tag event script on value changed that used the system.tag.writeBlocking with arguments ("path", 1). That works just fine however on my Boolean tag I have another script on value changed
image

It worked for a second, but then I tried using it on an actual counter then it didn't work, and I haven't gotten to work since. I'm only setting the delay for 10 sec because I didn't want to wait a min for something that doesn't work

Anything Helps, Thanks!

system.util.invokeLater doesn't exist in gateway scope.

That doesn't mean use some kind of sleep() call. It means you need to rethink your algorithm for an event-driven environment.

I recommend you use a memory tag and an expression tag with your script. The memory tag would hold a timestamp of the last change, written by the valueChange event on the counter tag.

If the two extra tags are in the same folder as the counter, the script would look something like this:

system.tag.writeAsync(['[.]LastChange'], [system.date.now()])

and the boolean expression tag Counting would look like this:

dateIsBefore(now(500), addSeconds({[.]LastChange}, 10))

(Make sure the expression tag is set to event driven mode.)

5 Likes

You guys are amazing, it worked perfectly