Logic Machine Forum
Modbus RTU Serial Enabled/Disabled by Script - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Gateway (https://forum.logicmachine.net/forumdisplay.php?fid=10)
+--- Thread: Modbus RTU Serial Enabled/Disabled by Script (/showthread.php?tid=2208)



Modbus RTU Serial Enabled/Disabled by Script - HannPark - 27.08.2019

Hi guys...

is there a way to activate and deactivate the Modbus RTU Serial 1 by an event script?, cuz´I want to use an object for doing this from the visualization without using the administrator account 

B.R


RE: Modbus RTU Serial Enabled/Disabled by Script - admin - 28.08.2019

What is the use case for that?


RE: Modbus RTU Serial Enabled/Disabled by Script - HannPark - 28.08.2019

Hi admin,

I'm trying to use 2 Modbus Masters writing in KNX(The LM and an external one)reading common devices but clearly not at the same time, so the master change should be done by the final user, switching between them without getting access over the LM config. That's why I want to set up a switch in user's visualization for make this change.

B.R


RE: Modbus RTU Serial Enabled/Disabled by Script - Daniel - 28.08.2019

This is not the best approach. You should make one device talking to slave and the other two masters should exchange data in another way. LM can be also modbus slave.


RE: Modbus RTU Serial Enabled/Disabled by Script - HannPark - 28.08.2019

Thanks Daniel,

But what happened if I had 2 masters reading same devices?, in Modbus that's imposible but...you can do it if you turn off one master when the other one is working, as I see.. that's like a redundant modbus network, that's the thing that I wanna get... it's easy from the admin account cuz' you just go to the modbus tab and disable RTU and it's done...but the tricky thing is to do it from the visualization...


RE: Modbus RTU Serial Enabled/Disabled by Script - admin - 30.08.2019

Use this event script to emulate a web request to enable/disable RTU. Attach it to a boolean object.

Code:
value = event.getvalue()

require('uci')
require('json')

function getvar()
  return 'config-save'
end

function json.data()
  return { enabled = value }
end

dofile('/lib/genohm-scada/plugins/modbus/web.lua')



RE: Modbus RTU Serial Enabled/Disabled by Script - HannPark - 30.08.2019

Thank u so much admin, it totally works!

B.R


RE: Modbus RTU Serial Enabled/Disabled by Script - Kilogica - 11.02.2022

Sorry, tried that script but it makes this error:

Code:
/lib/genohm-scada/plugins/modbus/web:0: attempt to index global 'ngx' (a nil value)
stack traceback:
/lib/genohm-scada/plugins/modbus/web: in function 'restart'
/lib/genohm-scada/plugins/modbus/web: in function </lib/genohm-scada/plugins/modbus/web:0>
/lib/genohm-scada/plugins/modbus/web: in function </lib/genohm-scada/plugins/modbus/web:0>
[C]: in function 'dofile'
User script:14: in main chunk



RE: Modbus RTU Serial Enabled/Disabled by Script - admin - 11.02.2022

Add this before the dofile call:
Code:
ngx = { sleep = os.sleep }



RE: Modbus RTU Serial Enabled/Disabled by Script - Kilogica - 11.02.2022

Thanks!