I have a digital opc tag which connect to a photo sensor, and have true value for several second and then go to false value. And I want to have a tag which count how many that digital tag has true value. What is the good solution to accomplish that?
Thank you, sorry for my bad English.
The best way would be with a transaction group as an Event Counter.
If you donāt have access to transaction groups (i.e you have Panel Edition), it getās a little more complicated.
Iāll post an example in a little bitā¦
Actually, itās going to be longer than a bit. Have a meeting to go to. 
Assumed, I have an access to Transaction group.
Ok, I will wait for the sample.
Best Regards
Update ā¦
Actually i do not have a transaction group.
But i am really appreciate if you provide a sample for both case studies.
With and without transaction group.
Best Regards
Hello Mr. Jordan,
I am waiting for your help, because I will perform demo to potential customer about Ignition.
Best Regards
Lets assume your OPC tag is called āMagic Tagā
Create a DB Tag Called āCounterā
Create a Tag Change Gateway Event Script. You can call it whatever you want. In āTag Pathsā, enter the path to Magic Tag
For the script, enter the following
counter = system.tag.getTagValue("Counter") #Gets the current value of the counter
if newValue.value == 1: #If this event was caused because the magic tag was set true
counter += 1 #Increment the counter value
system.tag.writeToTag("counter",counter) #write the new counter value to the "Counter" tag
Save the project and count away
2 Likes
If you want a cumulative true time,. try the following in addition to the previous code.
Create 2 more tags, "LastChangeTimestamp (DateTime) and CumulativeTrueTimeInSeconds(Int8)
counter = system.tag.getTagValue("Counter")
if newValue.getValue() == 1:
counter += 1
system.tag.writeToTag("LastChangeTimestamp",newValue.getTimestamp())
else:
time = system.tag.getTagValue("CumulativeTrueTimeInMilliseconds")
lastFallingTransition = system.tag.getTagValue("LastChangeTimestamp")
time += newValue.getTimestamp().getTime() - lastFallingTransition.getTime()
system.tag.writeToTag("CumulativeTrueTimeInMilliseconds",time)
system.tag.writeToTag("counter",counter)
Sorry, Yopie, Iāve been away for a bit.
Kyle has is exactly right. This is the best way to go about it without a transaction group.
Using a transaction group, you can set any item in the group to be a counter by using the āEvent meter optionā
Superbb, i am just searching for tag change event.
I think that is the best way to perform counter calculation.
Iāve also have try using Transaction Group.
Thank you Kyle and Jordan.
I am really appreciate it.
I have successfully create the counter, but
i have trouble displaying LastChangeTimestamp on the label control.
The label did not updated when āMagic Tagā changed.
[quote=āKyle Chaseā]If you want a cumulative true time,. try the following in addition to the previous code.
Create 2 more tags, "LastChangeTimestamp (DateTime) and CumulativeTrueTimeInSeconds(Int8)
counter = system.tag.getTagValue("Counter")
if newValue.getValue() == 1:
counter += 1
system.tag.writeToTag("LastChangeTimestamp",newValue.getTimestamp())
else:
time = system.tag.getTagValue("CumulativeTrueTimeInMilliseconds")
lastFallingTransition = system.tag.getTagValue("LastChangeTimestamp")
time += newValue.getTimestamp().getTime() - lastFallingTransition.getTime()
system.tag.writeToTag("CumulativeTrueTimeInMilliseconds",time)
system.tag.writeToTag("counter",counter)
[/quote]
Dear Kyle,
I have successfully create the counter, but
i have trouble displaying LastChangeTimestamp on the label control.
The label did not updated when āMagic Tagā changed.
Is there something Iāve missed?
Regards
One more thing :
Iāve created two counter tag, InputCounter and OutputCounter.
All the counter are updated through Gateway Script Tag Change Event.
Here are the script :
InputCounter (updated when AInput tag changed)
[color=#0000FF]counter = system.tag.getTagValue(āInputCounterā)
if newValue.value == 1:
counter += 1
system.tag.writeToTag (āInputCounterā, counter) [/color]
OutputCounter (updated when NInput tag changed)
[color=#0000FF]
counter2 = system.tag.getTagValue(āOutputCounterā)
if newValue.value == 1:
counter2 += 1
system.tag.writeToTag (āOutputCounterā, counter2)[/color]
The problem is only InputCounter are updated, the OutputCounter always have zero value although the NInput tag value changed.
Also i try to get timestamp value when AInput value changed through the following script :
[color=#0000FF]
system.tag.writeToTag (āGlassDigitalStatus\tAInputā, newValue.getTimestamp())[/color]
Tag āGlassDigitalStatus\tAInputā has TimeStamp data type.
But, the tAInput tag always got null value.
My goal is getting time difference between NInput and AInput.
Is there any idea how to solve this?
Best Regards
My guess is there is a problem around:if newValue.value == 1:
counter2 += 1
I would put print statements or add an else to see what is going on:if newValue.value == 1:
counter2 += 1
else:
counter2 = 10
You have to make sure the script is firing and the value is what you expect. If you do print to the console you can check the print out in the wrapper.log file located in:
c:\program files\inductive automation\ignition\logs