No image state loading when signal quality != 'Good'

i do not want to look at an empty image error placeholder when the incoming signal quality is not 'Good'. so i built the following binding on a custom prop isOn. the idea being if the signal stinks, i can look at a nice image telling me that. when it comes back online, i can then view the relevant switch states. problem is, this isn't working. i'm still seeing things that make me cry:

Screenshot 2023-12-20 151651

here's the code i bound to the image source (bear in mind isOn is a custom prop bound to a Tag's boolean flag):

def transform(self, value, quality, timestamp):  #<-- from isOn prop
	if quality != 'Good':
		return '/system/images/development/btn_noSIG.svg'
	elif value:
		return '/system/images/development/btn_ON.svg'
	else:
		return '/system/images/development/btn_OFF.svg'

the Binding Preview evaluates successfully AND correctly. but my eyes are still accosted when i load the page. what am i missing here?

Quality is a rich object, not a simple string. Maybe quality.isGood() as your conditional. Or isNotGood().

2 Likes

If you can do it with an expression binding then do. It's faster. Does this work for you?

if(isGood({[default]MyTag}),
	if({[default]MyTag},
		'/system/images/development/btn_ON.svg',
		'/system/images/development/btn_OFF.svg'
	),
	'/system/images/development/btn_noSIG.svg'
)
3 Likes

haven't used these much. but you had me at "faster". :smiley:

i'll give that a whirl now.

EDIT: works like a charm. and i learned a lot of new stuff. thank you! :+1:

Always go for an expression over a script when possible.

2 Likes

This was the primary motivation for this summer's Integration Toolkit expansion:

If you care about speed, read the whole thing.

4 Likes

there's only TWO places i don't care about speed: Government Policy Making by Idiots and just about anything where i'm naked. so i have some Christmas reading ahead of me. :books:

3 Likes

This forum estimates the time commitment:

There are 87 replies with an estimated read time of 35 minutes.

May not need to wait for Christmas. (:

sorry. had to modify the solution, because it doesn't work as constituted. so i just modified it so it reflects both the driving state (from the Tag) that determines if it shows the NO-SIG, and the subsequent flag needed to populate ON//OFF.

if(isGood({[IansTCG4Tags]Assets/LeDevice/Node/Tags/dOutput1}),
	if({this.props.isOn},
		'/system/images/development/btn_ON.svg',
		'/system/images/development/btn_OFF.svg'
	),
	'/system/images/development/btn_noSIG.svg'
)

ALL credit goes to @Transistor because the original post is his, i just modified it to behave correctly. plus i also got to learn about expressions in a way i never knew before. all around making me a better wunderkind. :wink:

it still fails when it goes offline, dammit, but i don't know what to do about that right now. the NO-SIG image should load, but it doesn't... and i don't know what to chase down. in theory, we're done here, i guess.

HAVE A MERRY CHRISTMAS YOU FABULOUS REPROBATES!! :partying_face:

God bless and keep you. I'll be back in the New Year.

just a quick edit. this solution feel somewhat flakey in that the browser/HMI needs refreshing a couple times before it displays properly. so i'm thinking it's a cache thing, which is out of scope here. but for those that follow: clear your caches!

EDIT: this also applies when the device goes offline. it reverts to the eyesore red box until you refresh the browser/HMI. very odd.

I would expect isGood to work on a tag even if the source is offline. It still works on one of my CNC tags even when the machine is off.

Maybe try this instead

try(
	if({this.props.isOn} && isGood({[IansTCG4Tags]Assets/LeDevice/Node/Tags/dOutput1}),
		'/system/images/development/btn_ON.svg',
		'/system/images/development/btn_OFF.svg'
	),
	'/system/images/development/btn_noSIG.svg'
)