Add to Expression Tag Value

Here is what I am trying to accomplish; Test a condition and if true, add 100, to its value, otherwise, do nothing.
The “test” condition works correct:
IF ({[.]…/COC/04_COC} = “32.50.207.500” && {[~]Kepware/TCP505/CAN_STOP/C_Bits/INVENT_100CNT_W04} =1, 1,0)
But when i try to change the “if true” to +100, it errors and even if it worked, it would revert to “0” when the condidtion was false.

Also, any suggested reading to where i would not have to bother you with small items like this?

Any help, as always, is greatly appreciated

Thanks!

You mean adding it to itself? I don’t think you can do that. In fact, I’m pretty sure you really shouldn’t do that.

Say if I had a tag that came in at 123. If the condition was true, it would go to 223. Well and good. But what happens if it’s still true on the next scan? It would then go to 323, 423, 523, and keep on going until the condition wasn’t true anymore. Not the most desirable of outcomes. :open_mouth:

I would make another tag with your expression:

IF ({[.]../COC/04_COC} = "32.50.207.500" && {[~]Kepware/TCP505/CAN_STOP/C_Bits/INVENT_100CNT_W04} =1,[]originalTagName+100,[]originalTagName)

Thanks Jordan,
Makes sense what you said about the scan updating the count each time it would run. Yep, that would definitely be a bad idea. I tried many different ways to make your solution work, but could never it get it to do so properly, most of the time it wanted to do, just as you said, increase every scan. So, been searching around the site for alternatives and came across a posting from you, “Event Meter” where you were trying to do exactly what i want to accomplish. I read it several times and been looking for the “Event Meter” and can not locate it. Just looking to count up one, every time the earlier mentioned condition became true. Adding 100 would be the goal, but I can multiply that in later.

Can you direct me to what you called the “Event Meter”

Thanks again

Have you considered a Tag Change Script or if your useing 7.7 then a Tag Event on a value changed event on the evulating tag.

somthing like

tagvalue = system.tag.read("tag2")
if currentValue.value == 1:
    tagvalue.value = tag +100
   system.tag.write("tag2",tagvalue.value)

Chris

[quote=“ilikebeer”]Thanks Jordan,
Makes sense what you said about the scan updating the count each time it would run. Yep, that would definitely be a bad idea. I tried many different ways to make your solution work, but could never it get it to do so properly, most of the time it wanted to do, just as you said, increase every scan. So, been searching around the site for alternatives and came across a posting from you, “Event Meter” where you were trying to do exactly what i want to accomplish. I read it several times and been looking for the “Event Meter” and can not locate it. Just looking to count up one, every time the earlier mentioned condition became true. Adding 100 would be the goal, but I can multiply that in later.

Can you direct me to what you called the “Event Meter”

Thanks again[/quote]

Wow. Need my wayback hat for that one… :laughing:

Event meters are part of transaction groups and is a mode settable with expression items.
https://inductiveautomation.com/support/usermanuals/ignition/triggered_expression_item.htm

Hi,

Yes, event meters are in transaction groups, but we will eventually add them to tags (it’s been a request for a while).

Anyhow, I think you might be able to do what you want by using the “hasChanged” function to prevent constant accumulation. Something like (assuming the expression tag is called ‘Adder’):

if({[.]../COC/04_COC} = "32.50.207.500" && hasChanged({[~]Kepware/TCP505/CAN_STOP/C_Bits/INVENT_100CNT_W04}) && {[~]Kepware/TCP505/CAN_STOP/C_Bits/INVENT_100CNT_W04} =1, coalesce({Adder},0)+100, coalesce({Adder},0))

So, the only extra trick here is the “coalesce” that will handle the initial state of the tag being “null”, having just been created, which would cause a type error on the first addition.

Hope this helps…

Sorry it took so long to get back with you all, and thank you for the assistance! I really appreciate all the advice and help! The last suggestion by Colby works excellently! Now, to figure out how to do the rest of what I’m heading for… I’ll probably be back soon for some more much needed guidance

Thanks again, everyone!