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?
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.
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.
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.
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).
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:
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
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.
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.