Scripting for a MOA switch in Ignition 8

I am trying to script an MOA tag in Ignition but it keeps giving me the same error. Syntax Error on Token: ‘BOUND CONST’ (Line 1 , Char 31). Here is the code itself attached to the Multi-State Switch and the MOA tag.

if {[.]../digital/cr_minus_bit} == 0:
    {[.]../bypass/cr_minus_bypass} = True
    {[.]../bypass/cr_minus_bypass_off} = False
if {[.]../digital/cr_minus_bit} == 1:
    {[.]../bypass/cr_minus_bypass} = False
    {[.]../bypass/cr_minus_bypass_off} = False
if {[.]../digital/cr_minus_bit} == 2:
    {[.]../bypass/cr_minus_bypass} = False
    {[.]../bypass/cr_minus_bypass_off} = True

Any help at all would be appreciated.

You can’t make assignments in the expression language. You return a value.

1 Like

Additionally in the expression language you use a single = for comparison. You would also need parentheses around your if( {[.]…/digital/cr_minus_bit}=0, 'someTrueValue', 'someFalseValue') statement. Check out the documentation here -
https://docs.inductiveautomation.com/display/DOC80/if

You’ve tagged your post with python, and your script looks kinda like python, but you’re using the expression style {tag}. Which are you using, python or expression ?

For expression, see posts above.
For python, you can’t access tags like this, you need to use system.tag.readBlocking/readAsync and system.tag.writeBlocking/writeAsync functions.
Also, if you’re using python, I’d suggest reducing the number of if statements:

minus_bit = system.tag.readBlocking(["path/to/minus_bit_tag"])[0].value

bypass = minus_bit == 0
bypass_off = minus_bit == 2

system.tag.writeBlocking(["path/to/bypass_tag", "path/to/bypass_off_tag"], [bypass, bypass_off])

Brandon, please use the </> code formatting button when posting code. It will indent properly (important for Python) and give syntax highlighting. You can use the 🖉 edit link to fix your post.

I have tried using every tool I was given on here and still not working. Is it actually possible to write out an expression or scripting for a Manual Off Auto switch that Ignition will accept besides making a tag in the PLC?

Perhaps I missed this, but is this Vision or Perspective? It could make a difference, not sure.

Vision

The issue is that you can’t write to a tag using an expression. If you are looking to keep it all in the component, I’d recommend:

if event.propertyName == 'controlValue':
	
	if newValue == 0:
		event.source.bypassOn = True
		event.source.bypassOff = False
	elif newValue == 2:
		event.source.bypassOn = False
		event.source.bypassOff = True
	else:
		event.source.bypassOn = False
		event.source.bypassOff = False
2 Likes

Simplified further:

if event.propertyName == 'controlValue':
	v = event.newValue
	event.source.bypassOn = v == 0
	event.source.bypassOff = v == 2
4 Likes

This fix does make the values bidirectional right?

That script will update the custom properties. The custom properties, because they’re bidirectionally bound, will update the tags.

4 Likes

So I’m trying the custom properties fix, it works partially. it still will not change the values of the tags associated with the properties. They are OPC tags inside of a UDT instance.

You followed what @JordanCClark had above, bindings set to bidirectional?

By the way, not sure I would call this a fix, it’s pretty much how you do it. :slight_smile:

Yes, I followed what @JordanCClark had above to the letter, barring changing some things to fit the tag names, and it seems as if Ignition refuses to accept it.

Perhaps your tags are read only? Maybe try creating some test tags, making them memory, to isolate the OPC side of things?

I keep getting this error each time I select something on the MOA.
Capture

Well that’s important to know. :slight_smile:

Paste in the details of the error.

Paste as text and format with the </> button, please. Not a screenshot.

1 Like

Error message:
Error executing script for event: propertyChange
on component: comp1_unloader2_moa.

Details:
Traceback (most recent call last):
File “event:propertyChange”, line 2, in
NameError: name ‘value’ is not defined