Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.
Script help
-
. I have a ModBus device connected to Mango. I have a couple of ModBus Data Points. I then have a Meta Data point referencing the Modbus Data points with the following script.
var a=p1.value; var le=p9.value; var re=p10.value; if (le==true) { var x = " Left"; } else if (re==true) { var x = " Right"; } if (a>0) { var y = "Pkey"; var result = y +" "+ a +" "+ x; } else if (a==0) { var result = "No fault" else if(typeof(p9.value || p10.value)=='undefined'){var result = "No fault"} return result;
It works as expected except that it throws undefined errors into the result.
No fault 06:44:46
Pkey 1 undefined 06:44:44
Pkey 1 Left 06:44:37
No fault Feb 09 12:28
Pkey 1 undefined Feb 09 12:28
Pkey 1 Right Feb 09 12:28Could anyone possibly assist.
Many thanks,
Duncan
-
At a quick glance, it looks like you aren't handling when le and re might both be false. If that is the case, x is never initialized.
-
I think CraziFuzzy does have the root of what's causing that output, but there are some other things you might want to fix in your script,
(typeof(p9.value || p10.value)=='undefined')
will not work, anything that can be logical or'ed tends to be boolean by its very nature. You have to split that into
(typeof(p9.value) == 'undefined' || typeof(p10.value)=='undefined')
There is also no definition for result when a < 0 to return.