Scripting to reset serial (MODBUS) data source
-
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
-
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 } }
-
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 likeif(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'); }
-
@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..
-
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.