Setting Several Data Points at once
-
Anytime :)
-
Hi,
I have managed to set a couple of binary data points by using <ma-get-point-value>, as follows:
<div> <ma-get-point-value point-xid="DP03_CS01_UMABAS013" point="myPoint1"></ma-get-point-value> <ma-get-point-value point-xid="DP03_CS01_UMABAS012" point="myPoint2"></ma-get-point-value> <ma-get-point-value point-xid="DP03_CS01_UMABAS011" point="myPoint3"></ma-get-point-value> <ma-get-point-value point-xid="DP03_CS01_FCBAS009" point="myPoint4"></ma-get-point-value> <ma-button ng-click="myPoint1.setValue(false);myPoint2.setValue(false);myPoint3.setValue(false);myPoint4.setValue(false)" raised="true" palette="primary" label="ON" icon="power_settings_new" hue="hue-1"></ma-button> <ma-button ng-click="myPoint1.setValue(true);myPoint2.setValue(true);myPoint3.setValue(true);myPoint4.setValue(true)" raised="true" palette="warn" label="OFF" icon="power_settings_new" hue="hue-3"></ma-button>
Now, how to do the same with 100 points?
Based on what @Matt said, I understand I should create a watch list with this points and then use ma-watch-list-get, instead of 100 lines of ma-get-point-value.
The problem, How should the watch list be created? there are several options for this (can it be a static watch list?), Also, how to use ma-watch-list-get? I have tried everything that came to my mind (which is not a lot), without success.Thanks!
Best,
Rodrigo -
If you need to do that many, use an RQL query to pull all of the points and set them in a scripted datasource in a loop
OR
Write an angularJS Controller and use the mango api to set them all in one go
Fox
-
If you are going to need to be setting 100 data points I would consider using a scripting data source. Create a single Binary point in the scripting data source and add the 100 data points to the CONTEXT. Then write a loop in the script that sets all the context points to the value of the Binary points. On your dashboard, you then just set the scripting data source binary point.
-
Thanks Craig
-
Thanks guys!
Will give this a try and let you know how it goes.
Best,
Rodrigo -
Hi guys,
A question regarding the method @CraigWeb described, will this also work for the Advanced Scheduler?
Or should I enter all those points separately in the scheduler?Best,
Rodrigo -
Yes it will work since the advanced scheduler can be used to run a script on fire.
Fox
-
Thanks Mr. Fox!
Rodrigo
-
@craigweb
Hello guys, would you be able to provide some more help on how to write this loop?Thanks,
Rodrigo -
for (var pnt in CONTEXT_POINTS) { this[pnt].set(1); }
Fox
-
Hi Matt,
You are alway ready to help! Thanks for that.
I am not bening able to understand how to do this, I have created the Scripting Data Source and added to it, External Context Points (from other Data Sources), this points are the ones that turn devices ON or OFF. Like this
Then, I created the Binary data point with this properties
Would you be so kind of expanding your previous reply a little more with this data?
Thanks in advance.
Best,
Rodrigo -
Add all your modbus context points, PLUS one virtual datapoint that is settable. Make the virtual point the context point for firing. All other context points must not be ticked for firing the script.
Put inside the for loop:
if(this[pnt].xid==virtualpointxid){continue;} this[pnt].set..
Dont want the script point to set the virtual point and make it fire itself again.
Thus when the virtual point in the context is set, the script will run.
If using an advanced scheduler, make it set that virtual point when it shifts from low to high.Hope that enlightens you
Fox
-
thanks Matt, but I am not able to understand how to make it work :(
-
ok I shall write a complete solution for you tonight. Dont know what time it is where you are but I shall assemble it all for you later today.
Fox
-
@mattfox
Really! Awesome, do not worry about the time, here is 19:21 (March 5) now.
Paraguayan time.
I could read it later tonight or even tomorrow and try to apply it.Thanks a lot!
-
11:34 AM here NZDT.
Ill have something here for you by breakfast :)
-
You are the best!
-
OK!
First off, apologies Rodrigo. I can see where you got lost. The script was marginally more involved than I first suspected...
However. as promised: here is the solution for you to learn from and apply for your own personal use.I have 3 batches of JSON for you to import and view to appreciate what to do. I have modelled this with virtual data sources for a proof of concept which can be applied in other places.
Virtual Datasource + points:
{ "dataSources":[ { "xid":"DS_233ecafd-78eb-4837-98fc-8cbdb35430bc", "name":"Temp Virtual", "enabled":true, "type":"VIRTUAL", "alarmLevels":{ "POLL_ABORTED":"URGENT" }, "purgeType":"YEARS", "updatePeriods":1, "updatePeriodType":"MINUTES", "polling":false, "quantize":false, "useCron":false, "editPermission":"", "purgeOverride":false, "purgePeriod":1 } ], "dataPoints":[ { "xid":"DP_c0_temperature", "name":"Temp 1", "enabled":true, "loggingType":"ALL", "intervalLoggingPeriodType":"MINUTES", "intervalLoggingType":"AVERAGE", "purgeType":"YEARS", "pointLocator":{ "dataType":"NUMERIC", "changeType":{ "type":"NO_CHANGE", "startValue":"10" }, "settable":true }, "eventDetectors":[ ], "plotType":"SPLINE", "rollup":"NONE", "unit":"", "simplifyType":"NONE", "chartColour":"", "chartRenderer":{ "type":"IMAGE", "timePeriodType":"DAYS", "numberOfPeriods":1 }, "dataSourceXid":"DS_233ecafd-78eb-4837-98fc-8cbdb35430bc", "defaultCacheSize":1, "deviceName":"Temp Virtual", "discardExtremeValues":false, "discardHighLimit":1.7976931348623157E308, "discardLowLimit":-1.7976931348623157E308, "intervalLoggingPeriod":1, "intervalLoggingSampleWindowSize":0, "overrideIntervalLoggingSamples":false, "preventSetExtremeValues":false, "purgeOverride":false, "purgePeriod":1, "readPermission":"", "setExtremeHighLimit":1.7976931348623157E308, "setExtremeLowLimit":-1.7976931348623157E308, "setPermission":"", "tags":{ }, "textRenderer":{ "type":"ANALOG", "useUnitAsSuffix":false, "suffix":"", "format":"0.00" }, "tolerance":0.0 }, { "xid":"DP_c1_temperature", "name":"Temp 2", "enabled":true, "loggingType":"ALL", "intervalLoggingPeriodType":"MINUTES", "intervalLoggingType":"AVERAGE", "purgeType":"YEARS", "pointLocator":{ "dataType":"NUMERIC", "changeType":{ "type":"NO_CHANGE", "startValue":"10" }, "settable":true }, "eventDetectors":[ ], "plotType":"SPLINE", "rollup":"NONE", "unit":"", "simplifyType":"NONE", "chartColour":"", "chartRenderer":{ "type":"IMAGE", "timePeriodType":"DAYS", "numberOfPeriods":1 }, "dataSourceXid":"DS_233ecafd-78eb-4837-98fc-8cbdb35430bc", "defaultCacheSize":1, "deviceName":"Temp Virtual", "discardExtremeValues":false, "discardHighLimit":1.7976931348623157E308, "discardLowLimit":-1.7976931348623157E308, "intervalLoggingPeriod":1, "intervalLoggingSampleWindowSize":0, "overrideIntervalLoggingSamples":false, "preventSetExtremeValues":false, "purgeOverride":false, "purgePeriod":1, "readPermission":"", "setExtremeHighLimit":1.7976931348623157E308, "setExtremeLowLimit":-1.7976931348623157E308, "setPermission":"", "tags":{ }, "textRenderer":{ "type":"ANALOG", "useUnitAsSuffix":false, "suffix":"", "format":"0.00" }, "tolerance":0.0 }, { "xid":"DP_c2_temperature", "name":"Temp 3", "enabled":true, "loggingType":"ALL", "intervalLoggingPeriodType":"MINUTES", "intervalLoggingType":"AVERAGE", "purgeType":"YEARS", "pointLocator":{ "dataType":"NUMERIC", "changeType":{ "type":"NO_CHANGE", "startValue":"10" }, "settable":true }, "eventDetectors":[ ], "plotType":"SPLINE", "rollup":"NONE", "unit":"", "simplifyType":"NONE", "chartColour":"", "chartRenderer":{ "type":"IMAGE", "timePeriodType":"DAYS", "numberOfPeriods":1 }, "dataSourceXid":"DS_233ecafd-78eb-4837-98fc-8cbdb35430bc", "defaultCacheSize":1, "deviceName":"Temp Virtual", "discardExtremeValues":false, "discardHighLimit":1.7976931348623157E308, "discardLowLimit":-1.7976931348623157E308, "intervalLoggingPeriod":1, "intervalLoggingSampleWindowSize":0, "overrideIntervalLoggingSamples":false, "preventSetExtremeValues":false, "purgeOverride":false, "purgePeriod":1, "readPermission":"", "setExtremeHighLimit":1.7976931348623157E308, "setExtremeLowLimit":-1.7976931348623157E308, "setPermission":"", "tags":{ }, "textRenderer":{ "type":"ANALOG", "useUnitAsSuffix":false, "suffix":"", "format":"0.00" }, "tolerance":0.0 }, { "xid":"DP_c3_temperature", "name":"Temp 4", "enabled":true, "loggingType":"ALL", "intervalLoggingPeriodType":"MINUTES", "intervalLoggingType":"AVERAGE", "purgeType":"YEARS", "pointLocator":{ "dataType":"NUMERIC", "changeType":{ "type":"NO_CHANGE", "startValue":"10" }, "settable":true }, "eventDetectors":[ ], "plotType":"SPLINE", "rollup":"NONE", "unit":"", "simplifyType":"NONE", "chartColour":"", "chartRenderer":{ "type":"IMAGE", "timePeriodType":"DAYS", "numberOfPeriods":1 }, "dataSourceXid":"DS_233ecafd-78eb-4837-98fc-8cbdb35430bc", "defaultCacheSize":1, "deviceName":"Temp Virtual", "discardExtremeValues":false, "discardHighLimit":1.7976931348623157E308, "discardLowLimit":-1.7976931348623157E308, "intervalLoggingPeriod":1, "intervalLoggingSampleWindowSize":0, "overrideIntervalLoggingSamples":false, "preventSetExtremeValues":false, "purgeOverride":false, "purgePeriod":1, "readPermission":"", "setExtremeHighLimit":1.7976931348623157E308, "setExtremeLowLimit":-1.7976931348623157E308, "setPermission":"", "tags":{ }, "textRenderer":{ "type":"ANALOG", "useUnitAsSuffix":false, "suffix":"", "format":"0.00" }, "tolerance":0.0 }, { "xid":"DP_c4_temperature", "name":"Temp 5", "enabled":true, "loggingType":"ALL", "intervalLoggingPeriodType":"MINUTES", "intervalLoggingType":"INSTANT", "purgeType":"YEARS", "pointLocator":{ "dataType":"NUMERIC", "changeType":{ "type":"NO_CHANGE", "startValue":"10" }, "settable":true }, "eventDetectors":[ ], "plotType":"SPLINE", "rollup":"NONE", "unit":"", "simplifyType":"NONE", "chartColour":"", "chartRenderer":{ "type":"IMAGE", "timePeriodType":"DAYS", "numberOfPeriods":1 }, "dataSourceXid":"DS_233ecafd-78eb-4837-98fc-8cbdb35430bc", "defaultCacheSize":1, "deviceName":"Temp Virtual", "discardExtremeValues":false, "discardHighLimit":1.7976931348623157E308, "discardLowLimit":-1.7976931348623157E308, "intervalLoggingPeriod":15, "intervalLoggingSampleWindowSize":0, "overrideIntervalLoggingSamples":false, "preventSetExtremeValues":false, "purgeOverride":false, "purgePeriod":1, "readPermission":"", "setExtremeHighLimit":1.7976931348623157E308, "setExtremeLowLimit":-1.7976931348623157E308, "setPermission":"", "tags":{ }, "textRenderer":{ "type":"ANALOG", "useUnitAsSuffix":false, "suffix":"", "format":"0.00" }, "tolerance":0.0 }, { "xid":"DP_dfd30a93-8ac3-40b7-aa7f-9f40b2a583a8", "name":"Trigger Point", "enabled":true, "loggingType":"ALL", "intervalLoggingPeriodType":"MINUTES", "intervalLoggingType":"AVERAGE", "purgeType":"YEARS", "pointLocator":{ "dataType":"NUMERIC", "changeType":{ "type":"NO_CHANGE", "startValue":"50" }, "settable":true }, "eventDetectors":[ ], "plotType":"SPLINE", "rollup":"NONE", "unit":"", "simplifyType":"NONE", "chartColour":"", "chartRenderer":{ "type":"IMAGE", "timePeriodType":"DAYS", "numberOfPeriods":1 }, "dataSourceXid":"DS_233ecafd-78eb-4837-98fc-8cbdb35430bc", "defaultCacheSize":1, "deviceName":"Temp Virtual", "discardExtremeValues":false, "discardHighLimit":1.7976931348623157E308, "discardLowLimit":-1.7976931348623157E308, "intervalLoggingPeriod":1, "intervalLoggingSampleWindowSize":0, "overrideIntervalLoggingSamples":false, "preventSetExtremeValues":false, "purgeOverride":false, "purgePeriod":1, "readPermission":"", "setExtremeHighLimit":1.7976931348623157E308, "setExtremeLowLimit":-1.7976931348623157E308, "setPermission":"", "tags":{ }, "textRenderer":{ "type":"ANALOG", "useUnitAsSuffix":false, "suffix":"", "format":"0.00" }, "tolerance":0.0 } ] }
Next the scripted data source that uses these points:
{ "dataSources":[ { "xid":"DS_dba43dbb-b0bf-497a-85f4-632ce54091d0", "name":"Rodrigo's Scripted trigger", "enabled":true, "type":"SCRIPTING", "alarmLevels":{ "SCRIPT_ERROR":"URGENT", "CONTEXT_POINT_DISABLED":"IGNORE", "DATA_TYPE_ERROR":"URGENT", "POLL_ABORTED":"URGENT", "LOG_ERROR":"URGENT" }, "purgeType":"YEARS", "updatePeriods":1, "updatePeriodType":"MINUTES", "updateEvent":"UPDATE", "context":[ { "varName":"t1", "dataPointXid":"DP_c1_temperature", "updateContext":false }, { "varName":"t2", "dataPointXid":"DP_c2_temperature", "updateContext":false }, { "varName":"t3", "dataPointXid":"DP_c3_temperature", "updateContext":false }, { "varName":"t4", "dataPointXid":"DP_c4_temperature", "updateContext":false }, { "varName":"trigger", "dataPointXid":"DP_dfd30a93-8ac3-40b7-aa7f-9f40b2a583a8", "updateContext":true }, { "varName":"t0", "dataPointXid":"DP_c0_temperature", "updateContext":false } ], "logLevel":"NONE", "scriptPermissions":[ "superadmin" ], "polling":false, "executionDelaySeconds":0, "historicalSetting":false, "logCount":5, "logSize":1.0, "script":"var triggerpt = trigger.getDataPointWrapper();\r\nfor (var pnt in CONTEXT_POINTS) {\r\n var pt = this[pnt].getDataPointWrapper();\r\nprint(pt.xid===triggerpt.xid);\r\n if(pt.xid===triggerpt.xid){continue;}\r\n else{\/\/we are not amending this point!!!! Do not want an infinite loop and a breakdown.\r\n pt.runtime.set( Math.random()*100 );\r\n }\r\n }", "quantize":false, "useCron":false, "editPermission":"", "purgeOverride":false, "purgePeriod":1 } ] }
Finally, here is your event handler which is tied to an advanced scheduler which I believe you requested in another thread....
{ "advancedSchedules":[ { "xid":"ADVSCH_25f85e3d-7c2b-4b80-9a50-93571e510896", "defaultSchedule":{ "dailySchedules":[ { "changes":[ "01:55", "02:00", "02:50", "03:00", "04:00", "04:05", "04:50", "05:00", "06:00", "06:05", "07:00", "07:05", "08:05", "08:10", "08:55", "09:00", "09:55", "10:00", "11:00", "11:05", "12:00", "12:05", "12:55", "13:00", "13:55", "14:00", "15:05", "15:10" ] }, { "changes":[ "01:55", "02:00", "02:50", "03:00", "04:00", "04:05", "04:50", "05:00", "06:00", "06:05", "07:00", "07:05", "08:05", "08:10", "08:55", "09:00", "09:55", "10:00", "11:00", "11:05", "12:00", "12:05", "12:55", "13:00", "13:55", "14:00", "15:05", "15:10" ] }, { "changes":[ "01:55", "02:00", "02:50", "03:00", "04:00", "04:05", "04:50", "05:00", "06:00", "06:05", "07:00", "07:05", "08:05", "08:10", "08:55", "09:00", "09:55", "10:00", "11:00", "11:05", "12:00", "12:05", "12:55", "13:00", "13:55", "14:00", "15:05", "15:10" ] }, { "changes":[ "01:55", "02:00", "02:50", "03:00", "04:00", "04:05", "04:50", "05:00", "06:00", "06:05", "07:00", "07:05", "08:05", "08:10", "08:55", "09:00", "09:55", "10:00", "11:00", "11:05", "12:00", "12:05", "12:55", "13:00", "13:55", "14:00", "15:05", "15:10" ] }, { "changes":[ "01:55", "02:00", "02:50", "03:00", "04:00", "04:05", "04:50", "05:00", "06:00", "06:05", "07:00", "07:05", "08:05", "08:10", "08:55", "09:00", "09:55", "10:00", "11:00", "11:05", "12:00", "12:05", "12:55", "13:00", "13:55", "14:00", "15:05", "15:10" ] }, { "changes":[ "01:55", "02:00", "02:50", "03:00", "04:00", "04:05", "04:50", "05:00", "06:00", "06:05", "07:00", "07:05", "08:05", "08:10", "08:55", "09:00", "09:55", "10:00", "11:00", "11:05", "12:00", "12:05", "12:55", "13:00", "13:55", "14:00", "15:05", "15:10" ] }, { "changes":[ "01:55", "02:00", "02:50", "03:00", "04:00", "04:05", "04:50", "05:00", "06:00", "06:05", "07:00", "07:05", "08:05", "08:10", "08:55", "09:00", "09:55", "10:00", "11:00", "11:05", "12:00", "12:05", "12:55", "13:00", "13:55", "14:00", "15:05", "15:10" ] } ], "offsetCount":196 }, "readPermission":"", "name":"Rodrigo's Scheduled trigger", "alarmLevel":"IMPORTANT", "errorAlarmLevel":"DO_NOT_LOG", "user":"admin", "editPermission":"", "enabled":true, "exceptions":[ ] } ], "eventHandlers":[ { "xid":"EH_c0202c22-1684-4216-ae68-5a9bc0cb1e82", "activeAction":"STATIC_VALUE", "inactiveAction":"NONE", "handlerType":"SET_POINT", "name":"Rodrigo's Automated Trigger", "targetPointId":"DP_dfd30a93-8ac3-40b7-aa7f-9f40b2a583a8", "disabled":false, "activeValueToSet":"1", "scriptPermissions":"", "eventTypes":[ { "XID":"ADVSCH_25f85e3d-7c2b-4b80-9a50-93571e510896", "sourceType":"ADVANCED_SCHEDULE", "scheduleEventType":"SCHEDULE_ACTIVE" } ], "additionalContext":[ ] } ] }
You can amend the schedules however you like.
To show how this works manually: here is some dashboard markup:
<ma-get-point-value point-xid="DP_c0_temperature" point="pt1"></ma-get-point-value> <ma-get-point-value point-xid="DP_c1_temperature" point="pt2"></ma-get-point-value> <ma-get-point-value point-xid="DP_c2_temperature" point="pt3"></ma-get-point-value> <ma-get-point-value point-xid="DP_c3_temperature" point="pt4"></ma-get-point-value> <ma-get-point-value point-xid="DP_c4_temperature" point="pt5"></ma-get-point-value> <ma-get-point-value point-xid="DP_dfd30a93-8ac3-40b7-aa7f-9f40b2a583a8" point="trigger"></ma-get-point-value> <md-button class="md-accent md-raised md-hue-2"ng-click="oldpt1=pt1.renderedValue; oldpt2=pt2.renderedValue; oldpt3=pt3.renderedValue; oldpt4=pt4.renderedValue; oldpt5=pt5.renderedValue; trigger.setValue(1); ">HIT ME!</md-button> <md-table> <table> <tr> <th>{{pt1.name}}</th><th>{{pt2.name}}</th><th>{{pt3.name}}</th><th>{{pt4.name}}</th><th>{{pt5.name}}</th> </tr> <tr> <!-- Current Values --> <td>{{pt1.renderedValue}}</td><td>{{pt2.renderedValue}}</td><td>{{pt3.renderedValue}}</td><td>{{pt4.renderedValue}}</td><td>{{pt5.renderedValue}}</td> </tr> <!-- Previous Values --> <td>{{oldpt1}}</td><td>{{oldpt2}}</td><td>{{oldpt3}}</td><td>{{oldpt4}}</td><td>{{oldpt5}}</td> </tr> </table> </md-table>
Ok, that's all of the config for you. Please have a good look and take note at how I applied the event handler settings.
The way I implemented allows the scheduler to set the virtual trigger the same way as if you had clicked the button on the dashboard.
HOWEVER, you can use the code in the scripted datasource and all of your context points and run the script inside the handler instead. But that is entirely up to you.
Good luck!Fox
-
Thank a lot Matt! I will be trying it this week and see how it goes.
I really appreciate your help.Best,
Rodrigo