Changing Label Properties based on Tag Values

I am trying to create a label for an HMI that will say if a part passed, failed, or if the machine is running. I started by creating an expression binding on the text property of the label that looks like this:


With this transformation script:

def transform(self, value, quality, timestamp):
	if value. Var1 == 0:
		value.text == 'TEST RUNNING'
	elif value.Var1 == 1 and value.Var2 == 1:
		value.text == 'TEST PASS'
	elif value.Var1 == 1 and value.Var2 == 0:
		value.text == 'TEST FAIL'

But I can't get it to return anything but null. I have tried to do this same thing but to change the color of the background but no luck.
Any idea what I am doing wrong?

You are not returning any value.

Try this:

def transform(self, value, quality, timestamp):
	if value.Var1 == 0:
		return('TEST RUNNING')
	elif value.Var1 == 1 and value.Var2 == 1:
		return('TEST PASS')
	elif value.Var1 == 1 and value.Var2 == 0:
		return('TEST FAIL')

Including {this.props.text} in your structure binding makes a circular reference. Perspective is pretty good about catching these, but not perfect. If it doesn't, it can bog down your gateway.

You should be able to use a direct Expression binding.

//  Ready   PassFail    Output
//  -----   --------    ------
//  False     X         TEST RUNNING
//  True      True      TEST PASS
//  True      False     TEST FAIL
if(!{[default]BurstTester/Instrument_Ready},
	'TEST RUNNING',
	if({[default]BurstTester/OverallPassFail},
	  'TEST PASS',
	  'TEST FAIL'
	)
)
1 Like

After playing around with this a few ways, I wasn't able to get it to work completely. I would still get the null value returned.

This seems to work exactly how I needed it to. I may need to look into it more to get it to work with changing different text colors and backgrounds.

Oh-oh!
It might be time for a read of High Performance HMI Techniques | Ignition User Manual.

In any case, you would copy the binding from the text property and apply it to the Style Classes and replace the text in the expression above with the style classes. (You wouldn't be applying colors directly in a binding now, would you?)

Thanks for the help! I was able to get everything to work as intended after a little reading.