Perspective custom element binding dataset refresh based on an OPC tag

Hello,

I have a Perspective view with a custom prop called Key which has named query binding pulling a dataset to display data on the view. One pallet slot holds 5 at a time. As the operator builds the next slot parts, the display data gets updated. Currently I am using absolute poll rate.

I want to use a tag value change script to refresh the query on ‘Key’ based on a OPC tag which increments for every part. If there is no change in the counter, I wouldn’t refresh thereby saving gateway some load. Is this achievable via a script? Or any other more suitable way?

Thanks

With a script you can use [path-to-component].refreshBinding([property-name])

Note that if the incrementing OPC tag value happens to be a parameter to the named query, then a change in it would automatically cause the query to refresh.

I have entered the following in the tag change script and it gives me a syntax error -’no viable alternative at input 21’ at Sta 21 User

def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
    [Sta_31_21_Interface/Sta 21 User/Sta 21 Interface].refreshBinding([key_3])

ProjectName/FolderName/ViewName and key-3 is the custom prop with query binding.

Not sure what I am doing wrong here. Thanks @Ryan_Deardorff

Is this a tag's Value Changed script or a gateway Tag Change Event script? Either way, you'll need to use system.util.sendMessage to send a message targeting any active session of the project with the view containing the binding.

system.util.sendMessage("Target Project", "refreshData", {}, scope="S")

Then have a Perspective Session Message handler defined in that project that re-echoes the received message to the active session using system.perspective.sendMessage with a scope of session.

system.perspective.sendMessage("refreshData", {}, scope="session")

From there, your view with the binding should have a message handler that will call refreshBinding on the associated object property.

self.view.refreshBinding("custom.key_3")

The other option would be to bind the target tag to a custom property on the view with the data binding and write a property Changed script to call refreshBinding on the data binding(@Ryan_Deardorff beat me to it).

2 Likes

I was thinking of a change script on a custom property that is bound to the tag, not a tag event change script.

Suppose your dataset is a custom view property data. You have another custom view property that is bound to the value of the OPC tag, and a change script on that:

def valueChanged(self, previousValue, currentValue, origin, missedEvents):
	self.refreshBinding("custom.data")
1 Like

This is a tag value change from the tag browser.

@Ryan_Deardorff I am using a lookup function on the dataset in key_3 to populate the fields on the view

I will try this during downtime. Thanks @ryan.white

I just tried this method @Ryan_Deardorff . It works great. Defined a custom prop with the OPC binding right under key_3 and ran change script on the new prop with a self.refreshBinding("custom.key_3") and it’s updating the dataset automatically. Thanks

Will have to try @ryan.white solution later. It’s interesting too

1 Like

Glad I could help.

I also recommend assigning meaningful names to your properties. I inherited a project where my predecessor left a bunch of unnamed ('key', 'key_1', etc.) properties, and found it frustrating trying to figure out what their purpose was. I've said the same about view component names--a little extra effort in the short term can save lots of hassle in the long run.

True..I inherited this with no knowledge of Ignition and first thing I will do is cleanup after I figure some things out.

1 Like

While this will work, I would recomend not going this route unless you have many such things to refesh at once. @Ryan_Deardorff's method is the more maintainable option.

3 Likes