Obtain value of point in javascript.
-
I need to get the value of a point in the javascript of my component, to perform some operations. In HTML, can I do with the ma-point value, but in javascript? Thank you
-
You can, but you'll have to do it with leveraging an angularjs controller and storing it in the userModule module.
https://help.infiniteautomation.com/getting-started-with-a-user-module?rq=usermodule
You'll have to use the maPointValues service. I'm not near a pc so I am unable to provide a code example at this time. -
@mattfox
Yes, I have created my components. In a parent component, I filter the points that I need and in a child component, I bind the point I need. Now, I need to make a logic with the point value in javascript.
I would appreciate an example of using the maPointValues service, thanks! -
Johana:
You might find this helpful. It is an example of a technique that I use in global scripts and scripting data sources.
var query = "eq(deviceName," + source.name + ")&eq(name,Auto Limit)"; var dataPoint = DataPointQuery.query( query ); if( dataPoint.size() ) { limit = dataPoint[0].runtime.value; } else { LOG.info( source.name + ": Auto Throttle: Auto Limit data point not found "); return; }
I am not sure whether this works in your context, but perhaps it might be helpful.
-
Does the code above not work inside a module?
-
@pyeager said in Obtain value of point in javascript.:
Does the code above not work inside a module?
No, this JavaScript is what runs inside
rhinonashorn and has access to Java methods (Hence the data point wrapper). The mango ui uses the rest api, hence why 3.6 can use the new ui to make various data sources and events and 3.5 cannot.For the code! Running on a few hours sleep here..
componentContriller.$inject=['maPointValues']; function componentController(maPointValues) { var opts={ latest:1, fields:['VALUE','TIMESTAMP','XID'], Rollup:'NONE' }; maPointValues.getPointValuesForXid('myXid',opts).then(function( values ){ console.log( values ); }); }
I'm not certain if this is the right way to do it, bit it's 'a' way. You may find using the websockets and writing a handler to get the job done works better. YMMV
Fox
-
Thanks for helping out @MattFox and @pyeager
Couple comments,
No, this JavaScript is what runs inside rhino
It's now the Nashorn engine as of Java 8. If there are still Rhino references in the documentation I will remove them if I am aware of them.
On the global script comment, I would encourage using global scripts only for defining functions or global variables. It looks like it probably was on @pyeager 's system (otherwise 'source' is only going to be defined for Point Links and everything else will error while preparing the script engine), but that part may have been omitted.
I'm not certain if this is the right way to do it, bit it's 'a' way. You may find using the websockets and writing a handler to get the job done works better.
You could also define the point as an input of the component in its controller and then pass it in from existing components, such as was done in this thread: https://forum.infiniteautomation.com/topic/3503/how-to-chart-with-data-points-in-the-x-axis-instead-of-time/5
-
It's now the Nashorn engine as of Java 8
Noted!
Thanks Phil, you da MVP ;)