• 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

    How to set a datapoint value by XID ?

    User help
    mangoapi
    3
    9
    3.1k
    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.
    • J
      Jenny
      last edited by

      We learned from the Forum that we can use mango core java call to get the datapoint value like this:

      function getDataPointValueByXID(xid){
      var pvd = this.pvd;
      if(!pvd) {
      pvd = this.pvd = com.serotonin.m2m2.Common.databaseProxy.newPointValueDao();
      }
      var dpid = com.serotonin.m2m2.db.dao.DataPointDao.instance.getDataPoint(xid).getId();
      var returnValue = String(pvd.getLatestPointValues(dpid,1)[0].value);
      return returnValue;
      }

      Is there a way to setDataPointValueByXid(xid) ?

      Thank's !

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

        Hi Jenny,

        Yes! Such a function in the Mango scripting environment could work like this,

        function setDataPointValueByXID(xid, value) {
          var dataPoints = DataPointQuery.query("eq(xid,"+xid+")");
          if( dataPoints.length !== 1 )
           throw "Data point with xid '" + xid + "' not found.";
          if( dataPoints[0].runtime === null )
            throw "Data point with xid '" + xid + "' is not running.";
          dataPoints[0].runtime.set(value);
        }
        

        This will go out like a normal set from a scripting environment to devices, and is subject to logging types. If you're saving history data, you could add a time argument and put this on a scripting data source with 'Saves historic' which will not send out the sets nor be subject to logging properties.

        J 1 Reply Last reply Reply Quote 0
        • J
          Jenny @phildunlap
          last edited by

          @phildunlap
          Dear Phil , thank's ! awesome!
          It looks like the version 3.3.x call system function has changed. Is there any documentation for us to refer to? The above getDataPointValueByXID function, how to write it will be more in line with the future standard fucntion call ?

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

            I would have to see the context for the code you posted to know what it was specifically trying to achieve. That's a good way to go if you want the last value stored in the database. If you know the point is running and you want cached values in the result, you can do something like,

            function getDataPointValueByXID(xid) {
              var dataPoints = DataPointQuery.query("eq(xid,"+xid+")");
              if( dataPoints.length !== 1 )
               throw "Data point with xid '" + xid + "' not found.";
              if( dataPoints[0].runtime === null )
                throw "Data point with xid '" + xid + "' is not running.";
              return dataPoints[0].runtime.value; //runtime object is like a context point 
                //i.e. runtime.pointValuesSince(time)
            }
            
            1 Reply Last reply Reply Quote 0
            • V
              Vincent Chu
              last edited by

              Hi Phil,
              Just now we upgraded to 3.6.2, and we found these call functions getDataPointValueByXID(xid) not function anymore !!

              Can you help us to check where the problem is?

              Thanks !

              Vincent.

              1 Reply Last reply Reply Quote 0
              • V
                Vincent Chu
                last edited by

                Hi Phil,
                It's really weird!
                It only happens in the newly defined scripting, but the original defined scripting can be executed!

                Vincent.

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

                  Hi Vincent,

                  That sounds to me like maybe the new script that you're using doesn't have adequate script permissions to the data point in question. Perhaps your old script has superadmin permission?

                  1 Reply Last reply Reply Quote 0
                  • V
                    Vincent Chu
                    last edited by

                    Hi Phil,
                    Thanks ! you are right !
                    It seems that the new version (3.6) Script permissions does not automatically bring in the author's permissions. It stays blank.

                    Vincent.

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

                      It should, but it doesn't look like it does in all cases. For instance, scripting appears to, but meta data points don't. I will bring this up, thanks for bringing it to our attention.

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