• 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

    Scripting to reset serial (MODBUS) data source

    Scripting general Discussion
    3
    5
    3.2k
    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

      We have been experiencing some problems with serial MODBUS devices failing to receive data (sending appears to continue functioning, as a deadman switch is properly being written to prevent a hard reset). The simple solution is to re-enable the data source, either by clicking the "save" icon in the data source settings page, or disabling/re-enabling the data source by toggling the green "enabled" button.

      I hope to automate this solution with a scripting data source that checks the "Slave 1 Monitor" data point, and if it is 0 (error/failure) reset the serial data source (disable & enable).

      The simple question is: Does anyone have experience with this? Please share any helpful information, solutions, caveats.

      The longer question is: Where do I find documentation to accomplish this enable/disable of the data source?

      Thanks in advance,

      Aldo

      1 Reply Last reply Reply Quote 0
      • D
        Dan M
        last edited by

        I made a script data source to do this..

        if(RuntimeManager.isDataSourceEnabled('DS_Modbus') === true)
        {
            if (--Condition that occurs that means you need to reset, i.e slave monitor shows datasource is offline--)
            {
                 RuntimeManager.disableDataSource('DS_Modbus');  // disable DataSource 
                 while (RuntimeManager.isDataSourceEnabled('DS_Modbus') === true) {}    //loops until DataSource is disabled since it might take a few seconds to disable depending on your timeouts, etc..
                 RuntimeManager.enableDataSource('DS_Modbus');    // re-enable DataSource  
                }
        }
        
        1 Reply Last reply Reply Quote 0
        • phildunlapP
          phildunlap
          last edited by phildunlap

          Thanks for contributing that Dan!

          I would consider putting a RuntimeManager.sleep(200); into that while loop, though. Also, the calls to runtime manager should be synchronous, so you shouldn't need to pause in the middle at all. Furthermore, should the disable data source fail (maybe you don't have permission to edit that data source?) you'll get stuck in the while loop.

          But otherwise, Dan's solution will work in a great number of Mango versions in a script polling periodically.

          What I'd do, if you're using the latest Mango, is have a scripting data source update on change of the slave monitor point (currently the best way to disable scripting data source polling is to use a year in your cron, like 0 0 0 1 0 ? 2050 but we'll probably add the ability to outright disable polling), or have an event detector with a script set point event handler on it, and in either case a script body like

          if(inCondition(slaveMonitor)) { //Could maybe move this logic into the event detector if not using a scripting data source
              RuntimeManager.disableDataSource('DS_Modbus');
              RuntimeManager.enableDataSource('DS_Modbus');
          }
          
          1 Reply Last reply Reply Quote 0
          • D
            Dan M
            last edited by Dan M

            @phildunlap said in Scripting to reset serial (MODBUS) data source:

            RuntimeManager.sleep(200)

            @phildunlap I tried to use the sleep code for something else but I get this:

            TypeError: { dataSourceEnabled(xid): boolean, enableDataSource(xid): -1 0 1, disableDataSource(xid): -1 0 1, dataPointEnabled(xid): boolean, enableDataPoint(xid): -1 0 1, disableDataPoint(xid): -1 0 1, } has no such function "Sleep" in at line number 3
            at line:

            is RuntimeManager.sleep(XXXX) a valid function? I've seen it posted elsewhere but its not working for me..

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

              Hi Dan,

              Perhaps your Mango is quite old? The sleep function was added sometime ago as a wrapper for Thread.sleep. You may still be able to do java.lang.Thread.sleep(XXXX); if you are using Java 8.

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