Check a bit to set or disable a alarm level in a moving analog indicator

Hi everyone,

I made a simple script in the binding of an alarm level inside an analog indicator that checks if a bit is true to get the value of a tag or disable the alarm level if it’s false.

The code is the following:

def transform(self, value, quality, timestamp):
	sAux = system.tag.readBlocking(self.view.params.TagPath+"/H_PAR")
	if value:
		value = sAux[0]
	else:
		value = "null"
	return value

It’s works partially, because the check on the bit is correct and the if works good too, the problem is that when it’s false and it return “null” the object gives error because it get the null as a string.

Is there a way to return a null correclty so that the designer doesn’t give error?

Could you use an empty string instead of null? So just the quote marks with a space in between?

I tried what you suggested and it works now, it still give the red mark on the property but as long as it doens’t show on the runtime it’s fine.

Thank you so much

1 Like

In Python, the equivalent value is None (without quotes).

To avoid performance bottlenecks down the road, try to avoid script transforms if possible. For a straightforward if statement like this, I recommend that you create a custom property bound to the tag in your readBlocking function, then change this transform to an expression transform, and convert your Python script there. Additionally, if your En_H tag is used more than once in this view, move that tag binding to a custom property as well, and convert this binding to an Expression only, with no transform, referencing the two custom properties you create.

1 Like

Thanks for the heads up, I wasn’t really aware about how to use the custom properties.

It also simplified the expression since it became like this now:

if({this.custom.sEn_L},{value},None)

Thanks again.

2 Likes