This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Modbus TCP connection datakom d-200 mk2
#2
There's no "read single register" function in modbus, this only applies to writing where there are two different commands for single/multiple registers.
Keep in mind that voltage registers are 32-bit so each value consists of 2 registers. This might be why profile was not working for you.
Another thing is that you should not close the connection after each run. Profiles also support this by enabling "persistent" connection mode.

See if this works for you:
Code:
if not mb then
  require('luamodbus')
  mb = luamodbus.tcp()
  mb:open('10.36.0.25', 502)
  mb:setresponsetimeout(5)

  res, err = mb:connect()
  if not res then
    log('modbus connect failed ' .. tostring(err))
    mb:close()
    mb = nil
  end
end

if mb then
  reg10240, reg10241, reg10242, reg10243, reg10244, reg10245, reg10246, reg10247 = mb:readregisters(10240, 8)
  
  if reg10240 then
    mains_l1_voltage = reg10240 * 0x10000 + reg10241
    mains_l2_voltage = reg10242 * 0x10000 + reg10243
    mains_l3_voltage = reg10244 * 0x10000 + reg10245
    genset_l1_voltage = reg10246 * 0x10000 + reg10247
    log('voltage values', mains_l1_voltage, mains_l2_voltage, mains_l3_voltage, genset_l1_voltage)
  else
    log('modbus read failed ' .. tostring(reg10241))
    mb:close()
    mb = nil
  end
end
Reply


Messages In This Thread
RE: Modbus TCP connection datakom d-200 mk2 - by admin - 22.02.2021, 08:02

Forum Jump: