Hi All , javascript function to change multi-modbus serial point value
-
hi all , i wanna to make an javascript function to loop into set of modbus settable points to change it's values , actually to toggle on/off each point depends on parameter that i should provide.
i found something here but it serve only one point value , lets say that my data points name are b1_r01,b1_r02,b1_r03,b1_r04 ... b1_r08 , i wanna to change it's values after pressing on a button in a page using dashboradV3.1.
and here the script i found:
<script>function togglePoint( dataPointXid ) {
var getPoint = new XMLHttpRequest();getPoint.addEventListener('load', function() { //Consider returning if empty response text var point = JSON.parse( this.responseText ); point.enabled = !point.enabled; var putPoint = new XMLHttpRequest(); putPoint.open('PUT', '/rest/v1/data-points/'+point.xid, true); putPoint.setRequestHeader( 'X-XSRF-TOKEN', /XSRF-TOKEN=(.*?);/.exec(document.cookie)[1] ); putPoint.setRequestHeader( 'Accept', 'application/json' ); putPoint.setRequestHeader( 'Content-Type', 'application/json' ); putPoint.send(JSON.stringify(point)); }); getPoint.open('GET', '/rest/v1/data-points/'+dataPointXid, true); getPoint.setRequestHeader( 'X-XSRF-TOKEN', /XSRF-TOKEN=(.*?);/.exec(document.cookie)[1] ); getPoint.setRequestHeader( 'Accept', 'application/json' ); getPoint.send();
};
togglePoint("F6_B01_R01");
</script> -
Hi Joe,
Sorry this took so long to respond to. Is that toggle function working for you? You could tie your button to call a function that calls the toggle function several times,
function toggleStuff() { togglePoint("F6_B01_R01"); ... togglePoint("F6_B01_R08"); }
but perhaps your question is more complex? There are also endpoints for updating several data points at once, if you wished to make fewer API round trips, the /rest/v1/data-points endpoint (not data point xid, must be supplied in each point in the list in the PUT content.