Writing to tags in expressions

Hey there, im kinda lost with the expression language as it makes almost no sense to me coming from a c background.

Im attempting to write to two different tags from a toggling on/off button (tags are Enabled and Off in ignition which then relay to the PLC over opc-ua connection) So what im attempting to do is when the control value = 1 write the Enabled tag to 1 and Off tag to 0, and vise versa when control value is 0.

To save my life i cannot find how to write to a tag in the expression language. There are plenty of reading tag examples, but trying to set certain tags to true/false is completely evading me. here is what im working with currently

if( {Well.2 State Toggle.controlValue} = 1,
	{Well/Injector/Enabled , 1}
	{Well/Injector/Off , 0}
else 
	{Well/Injector/Enabled , 0}
	{Well/Injector/Off , 1}
)

Well, if it makes you feel better - you can’t find it because it doesn’t exist.
The expression language is designed for one purpose - to return a single value: Expression (computer science) - Wikipedia

If you want to write to tags, use scripting. It looks like you’re working in Vision, based on the path you used. Consider using a property change script on your 2 state toggle (filtering to the controlValue property) and writing to your two output tags:

if event.propertyName == "controlValue":
	if event.newValue:
		system.tag.writeBlocking(["Well/Injector/Enabled", "Well/Injector/Off"], [True, False])
	else:
		system.tag.writeBlocking(["Well/Injector/Enabled", "Well/Injector/Off"], [False, True])

(N.B. you could also reduce duplication in this simple case to the equivalent below)

if event.propertyName == "controlValue":
	system.tag.writeBlocking(["Well/Injector/Enabled", "Well/Injector/Off"], [event.newValue, not event.newValue])
2 Likes

Im still rather new to ignition so i appreciate the informative reply. Thanks again.