<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Scripting to reset serial (MODBUS) data source]]></title><description><![CDATA[<p dir="auto">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.</p>
<p dir="auto">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 &amp; enable).</p>
<p dir="auto">The simple question is: Does anyone have experience with this? Please share any helpful information, solutions, caveats.</p>
<p dir="auto">The longer question is: Where do I find documentation to accomplish this enable/disable of the data source?</p>
<p dir="auto">Thanks in advance,</p>
<p dir="auto">Aldo</p>
]]></description><link>https://forum.mango-os.com/topic/1953/scripting-to-reset-serial-modbus-data-source</link><generator>RSS for Node</generator><lastBuildDate>Thu, 11 Jun 2026 23:28:52 GMT</lastBuildDate><atom:link href="https://forum.mango-os.com/topic/1953.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 26 Aug 2015 18:52:39 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Scripting to reset serial (MODBUS) data source on Tue, 06 Mar 2018 03:36:10 GMT]]></title><description><![CDATA[<p dir="auto">Hi Dan,</p>
<p dir="auto">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 <code>java.lang.Thread.sleep(XXXX);</code> if you are using Java 8.</p>
]]></description><link>https://forum.mango-os.com/post/17573</link><guid isPermaLink="true">https://forum.mango-os.com/post/17573</guid><dc:creator><![CDATA[phildunlap]]></dc:creator><pubDate>Tue, 06 Mar 2018 03:36:10 GMT</pubDate></item><item><title><![CDATA[Reply to Scripting to reset serial (MODBUS) data source on Sat, 03 Mar 2018 15:57:34 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/phildunlap" aria-label="Profile: phildunlap">@<bdi>phildunlap</bdi></a> said in <a href="/post/15564">Scripting to reset serial (MODBUS) data source</a>:</p>
<blockquote>
<p dir="auto">RuntimeManager.sleep(200)</p>
</blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/phildunlap" aria-label="Profile: phildunlap">@<bdi>phildunlap</bdi></a> I tried to use the sleep code for something else but I get this:</p>
<p dir="auto">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<br />
at line:</p>
<p dir="auto">is RuntimeManager.sleep(XXXX) a valid function? I've seen it posted elsewhere but its not working for me..</p>
]]></description><link>https://forum.mango-os.com/post/17549</link><guid isPermaLink="true">https://forum.mango-os.com/post/17549</guid><dc:creator><![CDATA[Dan M]]></dc:creator><pubDate>Sat, 03 Mar 2018 15:57:34 GMT</pubDate></item><item><title><![CDATA[Reply to Scripting to reset serial (MODBUS) data source on Mon, 25 Sep 2017 16:48:29 GMT]]></title><description><![CDATA[<p dir="auto">Thanks for contributing that Dan!</p>
<p dir="auto">I would consider putting a <code>RuntimeManager.sleep(200);</code> 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.</p>
<p dir="auto">But otherwise, Dan's solution will work in a great number of Mango versions in a script polling periodically.</p>
<p dir="auto">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 <code>0 0 0 1 0 ? 2050</code> 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</p>
<pre><code>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');
}
</code></pre>
]]></description><link>https://forum.mango-os.com/post/15564</link><guid isPermaLink="true">https://forum.mango-os.com/post/15564</guid><dc:creator><![CDATA[phildunlap]]></dc:creator><pubDate>Mon, 25 Sep 2017 16:48:29 GMT</pubDate></item><item><title><![CDATA[Reply to Scripting to reset serial (MODBUS) data source on Sun, 24 Sep 2017 18:45:14 GMT]]></title><description><![CDATA[<p dir="auto">I made a script data source to do this..</p>
<pre><code>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  
        }
}
</code></pre>
]]></description><link>https://forum.mango-os.com/post/15558</link><guid isPermaLink="true">https://forum.mango-os.com/post/15558</guid><dc:creator><![CDATA[Dan M]]></dc:creator><pubDate>Sun, 24 Sep 2017 18:45:14 GMT</pubDate></item></channel></rss>