Using tag data quality to set tag value

Hello, I am using Red Lion OPC connection to read and display the speed of a ski lift. The speed value controls the background color of lines, text labels and numeric labels. Obviously the ski lift must be powered up for the speed value to update. I am running the program right now and connecting to multiple ski lifts through the Red Lion OPC Server that is running. Several of the lifts that are not powered up are showing old speed values which are not correct and therefore the background colors are not correct. restarting the tag has no effect. All non-running ski lifts should have component backgrounds set to red. The data quality is showing as not connected which is what I would expect. I am trying to find a way to check the data quality and if it is anything other than good I want to force a value of 0 into the lift speed data tag so that all components bound to the lift speed value will update accordingly. I am guessing scripting is the way to do this but have had no luck yet. Any suggestions? Thanks in advance.

That’s a bit strange. Ignition offers a default of a red overlay if the tag value is bad. The Red Lion OPC server may not provide this information.

You didn’t state whether your application is Vision or Perspective but you should be able to do what you want either way. In Perspective you could check if the tag’s Quality value changes when the unit goes offline. If it does then modify the binding on your speed readout to use an expression. Here I’m using a tag called Ski lift speed. A quality value of 192 means all is good with the tag:

if(
	{[default]Ski lift speed.Quality} = 192,
	{[default]Ski lift speed},
	"Offline"
)

Change Offline to 0 if you like but I’d prefer to know that comms was down rather than have a spoofed zero value. ‘-1’ or ‘–’ are other options.

Improvement (see Paul Griffith’s post below)

if(
	isGood({[default]Ski lift speed}),
	{[default]Ski lift speed},
	"Offline"
)

That worked…thanks!

Using Vision. I used your expression on a custom property called “speed” so if I understand correctly this checks if the OPC data tag LiftSpeed.Quality is 192, if it is then set the value of “speed” to LiftSpeed.value, otherwise set “speed” to offline or whatever I choose?

I am not using default red overlay because this makes screen unusable for user due to component placements and the size of the overlays.

Interesting that the Quality value was 600 when disconnected then when the expression executed it got set to 192 but the displayed value was whatever I put in the expression. Tested this on a currently running ski lift and it worked when disconnecting/reconnecting.

Thanks again!

Your understanding is correct. See Tag Quality and Overlays - Ignition User Manual 8.0 - Ignition Documentation for more on quality values and overlays. Code 600 isn’t listed! Expand the tag in Tag Browser if you want to see all the properties available for interrogation - including Quality.

It may be worth your while spending a little time on getting the overlays working for you. It makes it clear what’s going on and the operator learns that it’s showing the last valid reading received which, in some circumstances, may be better than nothing.

I would generally recommend the isGood() function (isGood({[default]Ski lift speed}) rather than an explicit check for only one tag quality.

1 Like

Thanks, Paul. I’ve used that in the past and forgot about it. It’s much cleaner and clearer.

After further testing this is not working as I thought. Instead of setting the value of “speed” I am trying to change the visible property of a label.

this expression DOES NOT change the visible value when quality goes bad:

if(
isGood({[default]Santiago_LineSpeed.Quality}),
{Root Container.Santiago_Speed.visible} = true,
false
)

this expression DOES change the visible value to false when quality goes bad:

if(
({[default]Santiago_LineSpeed.Quality}) = 192,
{Root Container.Santiago_Speed.visible} = true,
false
)

but the visible property DOES NOT go back to true when quality goes from bad to good? I am currently using the “default” tag group with default values

I can only see “good” or “some kind of error” for data quality, cannot find a numerical value but based on above it seems logical that it is 192 when quality is good and when I tried 191 it set visible to false.

probably missing something very simple…thanks in advance

I looks like you are trying to assign to the .visible property in the expression. Expressions don’t have assignments. Just operators and function calls. The result is assigned to the bound property. If you need to control the visible property, that is where the binding should be. (And you don’t need an if function to return true/false from a boolean expression. Just use the expression.)

To elaborate on Phil’s answer,
isGood({[default]Santiago_LineSpeed})
returns a value true or false. (Note the lowercase constant names. Python uses True, False, None but the expression language uses true, false, null.)

To use this to control the label’s visibility, create an expression binding on the label’s visibility. Set the binding to isGood({[default]Santiago_LineSpeed})
and that’s it!

Tip: please use the </> code formatting button when posting code. This will preserve indentation and apply syntax highlighting.

Thanks for the replies!

tried Transistor’s method for controlling visibility…

To use this to control the label’s visibility, create an expression binding on the label’s visibility. Set the binding to isGood({[default]Santiago_LineSpeed.Quality})*
*> and that’s it!

This did not work. The data tag quality was good, I unplugged the network and the quality went bad but the visibility never changed? I tried the initial setting of the label’s visibility property at both true and false, neither made a difference.

Seems so simple…what am I missing?

We can’t tell you what you’re missing if you don’t show us what you did.

1 Like

Sorry, new to forum and still learning the standard protocols used…

I used:

isGood({[default]Santiago_LineSpeed.Quality})

as an expression in the binding of the label visibility and it did not change the visibility of the label when the data quality went from good to bad.

Try dropping the .quality.

isGood({[default]Santiago_LineSpeed})

That was my fault. I’ll edit my posts above. I forgot to take out the .Quality when I converted to isGood function.

Thanks.

Dropping the .quality does the opposite of what I would expect. The Santiago_LineSpeed is active and valid but the visibility of the label is now false, shouldn’t it be true?

Q1. What is the tag’s Quality value? (Check in the tag browser.)
Q2. What is the value of the label’s Visible property. (Check in the Vision Property Editor.)
Q3. Is there a link icon on the label’s Visible property.

Q1: Good
Q2: False
Q3: Yes, it is where I clicked to enter the expression

Q4: Are you 100% certain you’re using the right tag path and the right provider ? :smiley:

Yes, only have the Default tag provider in this project and a small number of tags.

I’m afraid you’re gonna have to start showing us screenshots.