Logic Machine Forum
Modbus TCP connection status - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Modbus TCP connection status (/showthread.php?tid=921)



Modbus TCP connection status - leonidas - 01.08.2017

Hello, 

Do anyone know a good way to detect if there is or there is no connection with Modbus TCP device?

Code:
require('luamodbus')

mb = luamodbus.rtu()
mb:open('/dev/RS485-1', 9600, 'E', 8, 1, 'H')
mb:connect()

mb:setslave(1)
mb:setresponsetimeout(100)

--                     --
-- some modbus reading --
--                     --

mb:close()



RE: Modbus TCP connection status - admin - 01.08.2017

mb:connect() will return nil plus error message when connection cannot be established. If it breaks afterwards then all read/write calls will act the same.