• 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

    Sharing Multisate text rendered names across metadata point scripts

    How-To
    2
    6
    1.6k
    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.
    • P
      Pedro
      last edited by

      I have several metadata point sources with data type = Multistate. These points are either replicated or evaluated by other metadata points. Using the numerical value in the script logic leads to unreadable code and increased potential for coding errors. What is the recommended way to share the Text Renderer names between metadata point scripts without incurring unnecessary computation overhead? Is there a function call that can be used? How could a global script be used without a cron jon to accomplish this?

      Currently I simply declare the Javascript equivalent of an enumerated datatype, but I have to paste it into each script. Each time I add another value, I have to copy/paste it into many other scripts. This is not optimal.

      var VFDRule = { // Poseidon Well VFDn valve rule:
       OFF: 0,
       RO1: 1, // valve open
       RO2: 2, // valve open
       Either: 3, // RO valve open
       Both: 4, // RO valves open
       ON: 5, // well flush
       FAULT: 6, // VFD fault, 
       LowHz: 7 
      };
      // example enum usage by one of the scripts
      if (my.value == VFDRule.Either) {
          if (Well2.value == VFDRule.Either || Well3.value == VFDRule.Either)
              return my.lastValue(1).value;
      }
      return my.value;
      

      If there's computational overhead, cron latency, or excess complexity, I'm better off using the sub-optimal copy/paste.

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

        Hi Pedro,

        Did you consider declaring this enumerated datatype in a global script? If you need to refer to it, you can place print(VFDRule); in while you're adjusting your scripts.

        1 Reply Last reply Reply Quote 0
        • P
          Pedro
          last edited by

          Thanks. I tried a global script. It's better than multiple copy/pastes, but it does not ensure consistency with each Multistate text renderer. The result is that I still paste the declaration into the script for reference, even if it's as a comment.

          The print is a good idea, but it did not work:

          Could not convert result "[object Object]" to Multistate
          

          Debug did not work either:

          LOG.debug(VFDRule);
          DEBUG 2017-12-21 09:46:20,185 - [object Object]
          

          It seems that I would have to declare a slightly redundant print method in the global script, following the enumerated type declaration. Then I would call it with VFDRule.print();

          Instead, I decided to paste a comment:
          //VFDRule is declared in global script named "Enumerated Multistates"
          in each multistate script. Although the state names are not displayed in the script, I know which global script to open in another tab. I can then be assured that the declaration is consistent with the script. In contrast, anything redundantly pasted into the script could become inconsistent with the global declaration. The only inconsistency I have to watch for now is the Multistate Text renderer.

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

            I believe the 'Could not convert result' means you were return'ing it. But, nevertheless, I should have suggested print(JSON.stringify(VFDRule));

            P 1 Reply Last reply Reply Quote 0
            • P
              Pedro @phildunlap
              last edited by

              I only tried return temporarily as the LOG.debug did not work. I sometimes do that just for the resulting print statement, then I deleted it before saving the script.

              Thanks, I forgot about stringify. I'm used to lower level languages.
              I'm using LOG.debug(print(JSON.stringify(VFDRule))); and it's working nicely.

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

                Glad to hear it! But, I think you may wish to get rid of the LOG.debug portion. print() doesn't return anything so you're logging undefined. My script looks like this:

                LOG.debug(print("test"));
                

                which produces the output:

                test
                DEBUG 2017-12-21 09:39:40,795 - undefined

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