• 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

    Is DataPointWrapper object accessible for a runtime object?

    Scripting general Discussion
    2
    12
    3.8k
    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.
    • AldoRamosA
      AldoRamos
      last edited by

      The easy example is for logging purposes:

          LOG.debug('validating source: ' + source.xid);
      

      That’s a relatively trivial and seemingly meaningless example, since LOG is only available in manual validation.

      More substantial is a script that resets a serial MODBUS DataSource, based on slave point state:

          if (false === slavePoint.value)
              resetDataSource(slavePoint.dataSourceXid);
      

      On the subject of LOG being unavailable at run-time, is there a way to add annotation in such a script?

      1 Reply Last reply Reply Quote 0
      • AldoRamosA
        AldoRamos
        last edited by

        Speaking of adding annotation, is it possible to create events within a script? e.g.

        createEvent(URGENT, "bad input: " + source.value);
        
        phildunlapP 1 Reply Last reply Reply Quote 0
        • phildunlapP
          phildunlap
          last edited by phildunlap

          Great examples, I see the merit. I did a look looking around and I think it would be very easy to add this in, so I'll bring it up to others and see what they think.

          That information, source.xid or slavePoint.dataSourceXid are both constant I would think, but I do understand it make writing the code a lot nicer not to have to look up the constant values of those things during script writing.

          What do you mean LOG is unavailable at runtime? If your log level for the item is set below the level called (i.e. debug is below info) then your calls to LOG.info() will appear in the file specified. Are you not experiencing that? I do not believe they go into the main ma.log, but I can't recall offhand.

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

            @AldoRamos said in Is DataPointWrapper object accessible for a runtime object?:

            Speaking of adding annotation, is it possible to create events within a script? e.g.

            createEvent(URGENT, "bad input: " + source.value);
            

            Not so directly, but of course it is possible. If this is a scripting data source, you could have an alphanumeric point on the script with a change detector that you set your event text to.

            Also you can throw "a javascript exception"; and that will be reported as an event on the point or data source of the appropriate type, but will of course exit the script.

            1 Reply Last reply Reply Quote 0
            • AldoRamosA
              AldoRamos
              last edited by

              From: About Mango Java Script:

              Logging

              Logging can be achieved during script testing on the edit page by enabling the logging level desired and then using the appropriate log statement.

              The implication was that it's only available on the edit page. It's been a while since I paid attention to that; I just haven't leave in the LOG calls in production.

              Again, annotation and events would be preferred in the long run.

              Throwing exceptions is a viable solution for some cases, so thanks for pointing that out

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

                I guess that document is due for an update. You'll notice beneath the log level select that it says the file path it will be logging to.

                Again, annotation and events would be preferred in the long run.
                

                What do you mean exactly by annotation, and what benefit do you conceive over going through a data point to trigger the event? One advantage of a point is that you'll get return to normal behaviors easily. So, if you use a Regex alphanumeric state detector for the state "ERROR:.*" then you will know when it returned to normal. You can call the variable name eventDispatcher or whatever to keep the code looking nice. eventDispatcher.set("ERROR: free lunch"); looks straightforward enough to me.

                AldoRamosA 1 Reply Last reply Reply Quote 0
                • AldoRamosA
                  AldoRamos @phildunlap
                  last edited by

                  @phildunlap said in Is DataPointWrapper object accessible for a runtime object?:

                  What do you mean exactly by annotation

                  I meant pointValue annotation, i.e. setting a point value and adding an annotation in the process:

                  target.set(1.23, '2017-07-12T12:34:56', "after much number crunching, this number was the crunchiest");
                  

                  The alphanumeric eventDispatcher solution is a great idea. Thanks!

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

                    Ah I understand. I'll keep that in mind when I'm looking into making the VOs available from the context points. Seems like that would be an easy function to add as well. Good suggestions!

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

                      Both these suggestions were added into Mango 3.2. Context points will have a method getDataPointWrapper() and there is a third set() signature for set(value, time, annotation)

                      Should be released in a couple weeks!

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

                        This was released in 3.2

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