Logic Machine Forum
Turck modbus communication - 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: Turck modbus communication (/showthread.php?tid=2767)



Turck modbus communication - CristianAgata - 31.07.2020

Hi everyone, I'm trying to communicate with a Turck gateway, I have write a simple resident script to ask cyclical a value of the power supply, it works for a n numbers of request then the Turck passes me  'nill'
Any suggest?
Best regards 

This is my script 

if not mb then
    require('luamodbus')
    mb = luamodbus.tcp()
  mb:open('192.168.0.162', 502)
  mb:connect()
  log('stato modebus ', mb)
end

-- loop while condition is met
while (1) do
  -- read from address 1000
value = mb:readinputregisters(9216)
  log('valore di value',value)
  -- wait for 1.5 seconds
os.sleep(5.5)
end


RE: Turck modbus communication - admin - 01.08.2020

As suggested earlier you should use a profile instead of a script.
Here's a script that handles disconnect correctly. Make sure that script sleep time is larger than 0.
Code:
if not mb then
  require('luamodbus')
  mb = luamodbus.tcp()
  mb:open('192.168.0.162', 502)
  res = mb:connect()
  log('stato modebus', res)
end

if mb then
  value = mb:readinputregisters(9216)
  log('valore di value', value)
  
  if not value then
    mb:close()
    mb = nil
  end
end



RE: Turck modbus communication - CristianAgata - 01.08.2020

Thank you so much. Now I've created the json file and it works fine.... Sorry but I'm new in the modbus world.