The expression language doesnât do assignments â itâs not java. The closest to what you showed would be something like (bound to the LED displayâs value):if({ToteLoop/L_2_2MPE1} = 65536,
{Root Container.LED Display.value}+1,
{Root Container.LED Display.value})Note that it returns a value â either the original value plus one, or the original value unchanged.
But this wonât be very reliable â it doesnât restrict itself to value changing to 65536 from some other value. Opening the window with value already 65536 will give you an extra increment.
Consider using a memory tag for the display value, with a tag change event on the original tag to do the increment. Then you can check for startup conditions and verify that the new value != the old value.
I donât think incrementing a value on a window object is the best approach. You would be better to use the tagâs âValue Changedâ event to increment another tag. The script will look something likeif currentValue.value == 65536:
system.tag.write("[~]counter", system.tag.read("[~]counter").value + 1)This may mean that you have to reset the counter when appropriate.
Iâm not sure why your tag would be called â/root container/recircâ. You should be creating the new tag using the SQL TAG Browser under the âTagsâ folder, not the âClientâ folder - this will ensure it is a SQLTag (which exists on the server) and not a Client tag (which exists on each client independently).
Hereâs the complete valueChanged script for a tag called ârecircâ under a folder called âTestâ:[code]def valueChanged(tagPath, previousValue, currentValue, initialChange, missedEvents):
ââ"
Fired whenever the current value changes in value or quality.
Arguments:
tagPath: The full path to the tag (String)
previousValue: The previous value. This is a "qualified value", so it
has value, quality, and timestamp properties.
currentValue: The current value. This is a "qualified value", so it has
value, quality, and timestamp properties.
initialChange: A boolean flag indicating whether this event is due to
the first execution or initial subscription.
missedEvents: A flag indicating that some events have been skipped due
to event overflow.
"""
if currentValue.value == 65536:
system.tag.write("[~]Test/recirc", system.tag.read("[~]Test/recirc").value + 1)
[/code]Make sure you indent thelines of code using tabs, not spaces.
thanks Al, thats really helpful, yes I have created my tags in the tags folder. so all ok there.
iâve created the code as follows for the tag of the photo eye (see attached code.jpg)
but i receive an error next to the tag in the tag browser (see error.jpg)
in this instance any change in value of my tag will indicate a product has passed by, so it may be simpler to change the code to enumerate for any chage of value
This script should run for any change so you can take whatever action you want when the tag value changes. You might also want to use the âinitialChangeâ flag to ensure it is not triggered on first run.
From your second screenshot, I can see that youâre missing a bracket after âsystem.tag.readâ. I would also use the tag browser (the small icon to the upper right of the script editor) to insert tag paths into the script to make sure they are correct.
Once your script is correct the error flag should hopefully disappear.
The tag is just represented by a string so you donât need the value property:if currentValue.value == 1 :
system.tag.write("[.]Pic_Tower_Count", 0)Have a look here for examples.
Remember to indent your code under the âifâ, either with spaces or a tab (but donât mix both in a script!).
This post is 8 years old, but I wanted to check if we still can't increment very well in expression language.
I am using an event script for uptime per machine on a production line.
Gateway is processing many scripts constantly, and are not as fast as expressions I think.
Incrementing is assignment, so no. You can call a script with runScript in a binding, where the script has such a side effect, but it's a hack. (So too with my objectScript().) Including the target property in an expression directly makes a circular reference, and the expression editor tries to stop you (because it blows up the CPU).