• 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

    Calling a user-defined function from different meta data point scripts

    Scripting general Discussion
    2
    6
    2.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

      Infinite Automation states "You can use the Global Scripts module to call a custom function from each meta data point." How exactly is this done?

      The Scripting Data Source wiki page states:

      Global scripts are automatically included in the script execution, such that functions and variables defined there are available. Note that if global scripts are changed, the scripting data source must be restarted to reload them.

      So I defined a function in a "Scripting data source" script window, validated it (confirmed by "Script completed successfully"), and then enabled the data source. However, I could not call the function from a meta data source:

      Script error: sun.org.mozilla.javascript.EcmaError: ReferenceError: "mySpecialFunction" is not defined. (#2) in at line number 2 in at line number 2

      What is the difference between a "Scripting data source" and a "Global Script?" How does one define a "Global Script?" What is the exact meta data point syntax required to call the function?

      Thanks for your help.

      JoelHaggarJ 1 Reply Last reply Reply Quote 0
      • JoelHaggarJ
        JoelHaggar @Pedro
        last edited by

        @Pedro The Global Scripts module is a separate icon on the main menu: upload-45f7f7d0-acab-45a8-a385-869d2896c605

        You can not define a global script in a scripting data source but you can call a global script from a scripting data source or meta data point.

        Let me know if that clears it up?

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

          Thanks, that clears it up: I thought with the Mango Enterprise download I had all the m2m2 modules, but apparently I must not, as it does not appear on my datasource list. I suppose I must download it separately.

          1 Reply Last reply Reply Quote 0
          • JoelHaggarJ
            JoelHaggar
            last edited by

            This module is not a data source. It appears on the main menu along with the sql console and other modules.

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

              I guess I confused them. Thanks.

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

                I could only find "Global Scripts" under the "Meta Data Source" and "Scripting Data Source" wiki headings. Consequently, it is unclear which of the "Scripting Data Source" recommendations also apply to global scripts (and also why I did not think to look at the icon bar for the Global Scripts). Specifically, the Scripting Data Source states:

                Note how the typeof function is used to determine if constants need to be defined. This is an effective way of initializing the script context upon startup of the data source.

                if (typeof(rho) == "undefined") {
                    rho = 28;
                    sigma = 10;
                    beta = 8/3;
                    dt = 0.01;
                }
                

                I have defined functions containing equations in Global Scripts. They contain implicit constant definitions. For example:

                return (2.43941E-7*W3 -0.5433*W2 +0.06*W+2.0)
                

                The function seems to be working fine, but I'm concerned about the "effective way" cited on the Scripting Data Source page. Should I pull those constants out of the equation and declare them within a typeof structure? What are the implications of not doing that? Performance? Memory? Memory leaks? Why is this recommended for a Scripting Data Source? Speed?

                Thanks.

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