• Recent
    • Tags
    • Popular
    • Register
    • Login

    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.

    Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website Mango 5 Documentation Website

    Chinese brand PSU_monitoring rs485 and Mango

    How-To
    3
    63
    43.5k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      hengst
      last edited by hengst

      Alright i got it. thnx.

      i had little play with :

      var busVoltage = /[0-9A-Fa-f]{46}([0-9A-Fa-f]{8}).*/.exec(source.value);
      var extractedValue = busVoltage[1];

      print (busVoltage[1]);

      Script result:
      42453939

      so that works, i found code for converting the hex to float, but no knowledge of writing (java) coding structure is a show stopper at the moment. but i do have fun learning , gehehe

      1 Reply Last reply Reply Quote 0
      • phildunlapP
        phildunlap
        last edited by

        Nice!

        All the scripts use JavaScript.

        1 Reply Last reply Reply Quote 0
        • H
          hengst
          last edited by hengst

          little update ,

          i found that i need to convert in javascript the with sort of

          function hex2float(num) {
          var sign = (num & 0x80000000) ? -1 : 1;
          var exponent = ((num >> 23) & 0xff) - 127;
          var mantissa = 1 + ((num & 0x7fffff) / 0x7fffff);
          return sign * mantissa * Math.pow(2, exponent);
          }
          
          
          
          window.alert (hex2float("0xA4703942"));
          //flipped does the trick
          window.alert (hex2float("0x423970A4"));
          // outcome 46,36..... ( not rounded )
          
          ``
          
          so little progress here.
          1 Reply Last reply Reply Quote 0
          • H
            hengst
            last edited by

            Perfectum Resultativum ;

            0_1478170444805_upload-5743d503-afdb-46f8-8648-2edc42e2fdcc

            1 Reply Last reply Reply Quote 0
            • H
              hengst
              last edited by

              now put all this in Mango needs again some pointers i think..

              1 Reply Last reply Reply Quote 0
              • H
                hengst
                last edited by

                i got this in " point links as script " , is this ok ?

                0_1478275755900_upload-2b88dd9b-44ca-49ba-82c2-ab67bf96dfa0

                and what to put in :

                the script - source script. ?

                i tried 1000 different combinations. and reading the wiki / manuals. but sorry, i don't
                get it...

                1 Reply Last reply Reply Quote 0
                • phildunlapP
                  phildunlap
                  last edited by

                  Looking at your message queue, there are no identifiers. I assume this is because this is always for the same point. You could connect the point link to a point directly representing that value, if there is only one point's value in a message. Otherwise, you'll want some identifiers so that your script can parse the message queue and set points identified by the identifier to the value. I would have the identifiers in an object, where the object looks something like...

                  { "identifier1" : p334, .....}
                  

                  Where p334 is the variable name for the context point of the script.

                  1 Reply Last reply Reply Quote 0
                  • H
                    hengst
                    last edited by

                    identifiers, object etc, is probably JavaScript terms....hmm and i was thinking it was almost done, gehehe.
                    i need a neighbor with programming skills ( the neighbors house is for sale btw )
                    so back to learning books ..

                    1 Reply Last reply Reply Quote 0
                    • phildunlapP
                      phildunlap
                      last edited by

                      Ha! Well, we'll see how the politics here go ;)

                      Identifier is just a name that you can use in both places. Object is a JavaScript term for things defined as { "key": value }. Other names are Map and Dictionary.

                      1 Reply Last reply Reply Quote 0
                      • H
                        hengst
                        last edited by

                        ok learned "Object"

                        Can someone point me some explanation links about :

                        var identifierMap = { "messageIdentifier" : contextPoint1 ....  } 
                        

                        cant find much on " indentifierMap " on internet somehow.

                        1 Reply Last reply Reply Quote 0
                        • phildunlapP
                          phildunlap
                          last edited by

                          That's just a variable name, so that later in the script you can type

                          var ident = "messageIdentifier";
                          identifierMap[ ident ].set( /*your value here*/ );
                          

                          Where context points are added to the script through the UI of the Scripting data source.

                          1 Reply Last reply Reply Quote 0
                          • H
                            hengst
                            last edited by

                            "messageIdentiefier" is the variable/object coming from point link script right ?

                            1 Reply Last reply Reply Quote 0
                            • phildunlapP
                              phildunlap
                              last edited by phildunlap

                              Yeah. It looks like right now you're setting message queue to something like

                              49.73;49.73;49.73;

                              The identifier would be useful if you have multiple values to get out of a message. You explicitly know their positions when you extract the values, so you can give them something you can identify them with. So instead your message queue may look like,

                              busVoltage-49.73;busVoltage-49.73;busVoltage-49.73;otherValue-106.2;yetAnotherValue-78.1;

                              such that you could identify where to set those values out to in the script.

                              1 Reply Last reply Reply Quote 0
                              • H
                                hengst
                                last edited by

                                this is what i got,

                                0_1478292636682_upload-dbe30c51-4e24-4816-b5c5-ae67b8d033fc

                                and point link details :

                                0_1478292718157_upload-66e0378e-4c51-419e-81e5-ae06d0dbb617

                                1 Reply Last reply Reply Quote 0
                                • phildunlapP
                                  phildunlap
                                  last edited by phildunlap

                                  I would then modify the

                                  return target.value + result + ";" ;
                                  

                                  to

                                  return target.value + "busvolt-" + result + ";" ;
                                  

                                  But I think you will want to support multiple data extractions from the same message, like,

                                  return target.value + "busvolt-" + result + ";otherMeasuredValue-" + result2 ;
                                  

                                  Also, you may have to have call parseFloat, like so:

                                  identifierMap[ messageInfo[0] ].set( parseFloat( messageInfo[1] ));
                                  1 Reply Last reply Reply Quote 0
                                  • H
                                    hengst
                                    last edited by hengst

                                    Well, looks something is working :

                                    0_1478299096889_upload-f087c10f-9c3c-4807-abed-a0e87d2523ed

                                    i ques this is normal ?

                                    1 Reply Last reply Reply Quote 0
                                    • H
                                      hengst
                                      last edited by

                                      Alright. made some changes as, reading where not what the should be. now i get the right results from reading the Hex.

                                      Script "message Queue"

                                      // get Hex from source
                                      
                                      var busVoltage = /[0-9A-Fa-f]{30}([0-9A-Fa-f]{16}).*/.exec(source.value); 
                                      var extractedValue = busVoltage[1];
                                      
                                      var PsuLoad = /[0-9A-Fa-f]{78}([0-9A-Fa-f]{16}).*/.exec(source.value); 
                                      var extractedValue = PsuLoad[1];
                                      
                                      // Alarm relays Bit ( 1 is Alarm )
                                      var Alarm = /[0-9A-Fa-f]{185}([0-9A-Fa-f]{1}).*/.exec(source.value); 
                                      var extractedValue = Alarm[1];
                                      
                                      // door alarm Bit (1 is Door open )
                                      var DoorAlarm = /[0-9A-Fa-f]{185}([0-9A-Fa-f]{1}).*/.exec(source.value); 
                                      var extractedValue = DoorAlarm[1];
                                      
                                      
                                      var message = busVoltage[1];
                                      
                                      function toASCII(message) {
                                        var result = "";
                                        while(message.length > 1) { //parse two characters at a time
                                           var charCode = message.substr(0, 2);
                                           result += String.fromCharCode( "0x" + charCode );
                                           message = message.substr(2); 
                                        }
                                        return result;
                                      }
                                      
                                      // swap bytes /hex
                                      
                                      function swap32(val) {
                                      return ((val & 0xFF) << 24)
                                             | ((val & 0xFF00) << 8)
                                             | ((val >> 8) & 0xFF00)
                                             | ((val >> 24) & 0xFF);
                                      }
                                      
                                      //print (message);
                                      
                                      
                                      function hex2float(num) {
                                          var sign = (num & 0x80000000) ? -1 : 1;
                                          var exponent = ((num >> 23) & 0xff) - 127;
                                          var mantissa = 1 + ((num & 0x7fffff) / 0x7fffff);
                                          return sign * mantissa * Math.pow(2, exponent);
                                      }
                                      
                                      
                                      function roundToTwo(num) {    
                                          return +(Math.round(num + "e+2")  + "e-2");
                                      }
                                      
                                      
                                      // covert Hex to String
                                      var subresult = (toASCII(message));
                                      // create human readabe number
                                      var result = (roundToTwo(hex2float("0x" +subresult)));
                                      
                                      // send payload
                                      return target.value + "MainAlarm-" + Alarm[1] + ";" + "Door-" + DoorAlarm[1] + ";" + "busvolt-" + result + ";" ;
                                      
                                      

                                      at this point i get as result : MainAlarm-0;Door-0;busvolt-53.68;

                                      thats correct.

                                      so i have right input , further i am still completely lost in how i should proceed.

                                      i added my other (modbus) device and thats straight forward , enter the source and add data points to it. thats easy.
                                      now why cant i see the logic for the other source..

                                      1 Reply Last reply Reply Quote 0
                                      • H
                                        hengst
                                        last edited by

                                        Did made some progress, via an other approach ;

                                        Created : tcp/ip source ( 2 sec update period )
                                        Created : Data Point to that :

                                             "loggingType":"NONE",
                                             "dataType":"ALPHANUMERIC",
                                             "queryable":true,
                                              "readCommand":"<your_hex_request_for_your_device>",
                                              "settable":false,
                                              "valueIndex":0,
                                              "valueRegex":".*",
                                        

                                        Created META-source
                                        Created : Data Point to that :

                                             "name":"DoorAlarm",
                                             "enabled":true,
                                             "dataType":"ALPHANUMERIC",
                                             "updateContext":true,
                                             "varName":"p110"
                                        

                                        added in script field :

                                        // get Hex from source
                                        
                                        // Alarm relays Bit ( 1 is Alarm )
                                        var DoorAlarm = /[0-9A-Fa-f]{185}([0-9A-Fa-f]{1}).*/.exec(p110.value); 
                                        var extractedValue = DoorAlarm[1];
                                        
                                        // payload
                                        return "DoorAlarm- " + DoorAlarm[1];
                                        

                                        ...

                                        So i added some other "Meta-data points" for other values.
                                        This works ok, and i can understand how it works.

                                        Now the first approach has probably benefits in setting up many same kind devices/values i guess , so i am focusing on that as well , as i would like to understand how that should work.

                                        1 Reply Last reply Reply Quote 0
                                        • phildunlapP
                                          phildunlap
                                          last edited by

                                          The first approach's benefit is just somewhat more efficiently extract many points' values from a single message. You can still do that with meta points, where the incoming message provides a context update to all the meta points. Also, you can return the DoorAlarm[1] in the meta point if the meta point is Numeric and it will be treated as a Numeric. The "DoorAlarm" string portion is just to identify the point in the object (map, dictionary) in the script, where the value portion would be set out to data points created on the scripting data source. Those points on the scripting data source would ultimately be used for displays or dashboards.

                                          1 Reply Last reply Reply Quote 0
                                          • H
                                            hengst
                                            last edited by

                                            Thanks Phil(lips) , i am going to play with it , little stupid off topic question :

                                            "How to purge all Information on "Urgent events" or "information " . seems there is no option/knob when viewing the list. ( clear dates , seem to do nothing when selected periode )

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post