How do I efficiently create a scripted data source (or similar) across multiple devices?
-
Sorry, but I had a hard time expressing the question. Let me see if I can make it more clear.
I have multiple devices I am simulating with with the Mango virtual data source, one data source per device.
For one of the devices, I have also created a scripted data source that sets one of the data points in the virtual data source according to other data points in the same source.
This works fine, but doesn't scale very neatly, as the scripted data source must be replicated for each device. Code duplication isn't good. I think I can probably create a global script to be called from each scripted data source, but that still seems overly messy. I would still be creating a scripted data source per device - this would just reduce the code defined in each one.
If I could associate the script with a watchlist, that would seem to solve the problem, but I don't see a way to do that.
Perhaps someone out there has a better idea?
-
Hi pyeager, welcome to the forum!
If I could associate the script with a watchlist, that would seem to solve the problem, but I don't see a way to do that.
Do you say this because you have a parameter in a watchlist you've created or something which you are selecting between? I do not understand how you're thinking of associate a script with a watchlist.
Have you had a play with the
DataPointQuery
context object? You can use RQL just like the watchlist builder.DataPointQuery.query(rql);
returns a list of DataPointWrapper objects, which are what you get from a context point when you call.getDataPointWrapper();
. Data point wrappers have a.getRuntime();
that will return the type of object manually added context points are, AbstractPointWrapper, or null if the point is disabled. -
I suppose that I thought of a watchlist because that is how I am selecting datapoints displayed on the dashboard.
I haven't looked into DataPointQuery yet. It seems that I could use that in a script that iterates over the data sources to perform control logic on each, which is the goal.
-
^ Has an example of a script that uses the watchlist's export to iterate over the XIDs that are in the watchlist. That's really more for static watchlists, but you could also get a watchlist's query string this way to pass to the RQL. There is a
DataPointQuery.byXid("DP_12345")
function as well to get a single DataPointWrapper.https://help.infiniteautomation.com/about-mango-java-script
Has information about the various context objects available to assist in writing scripts. Note from the first link, though, that you can invoke Java directly, making the scripting environment extremely powerful and flexible.