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.

luamodbus
#1
Hello
I'm looking for documentation of luamodbus library but I can't find any.
I've found these functions are implemented:


Code:
close
connect
open
readinputregisters
readregisters
readregisters
readregistervalue
rtu
setdebug
setresponsetimeout
setslave
tcp
writeregisters

Anything else?
LM5Lp, firmware: 2018.08.22 and 2021.12.15, FlashSYS v2, ARMv7 Processor rev 5 (v7l), kernel 4.4.151 and 4.4.259
Reply
#2
What functions do you need? Most cases are handled by profiles so direct ModBus access is not needed.
Reply
#3
I need to implement functions:

0x01 read control switch status - ???
0x02 read input status - ??? - Is it readinputregisters?
0x03 read register value - This can be readregistervalue but I'm not sure
0x05 write control switch value - ???
0x06 write register value - Maybe it is writeregisters?

The device is a cooler from China. I'm afraid I can't use profiles because this device is 'unique' in many ways. One of them is it returns the same packet in case the command was successful. And I've to read the packet and set feedback object according to this. Another problem is I have to process commands step by step and misuse can damage the device. I know it can be done by calling of GA but I see it too dangerous.

Unfortunately I don't know if I'm allowed to publish the specification I've got co I can't post it here.
LM5Lp, firmware: 2018.08.22 and 2021.12.15, FlashSYS v2, ARMv7 Processor rev 5 (v7l), kernel 4.4.151 and 4.4.259
Reply
#4
If the device does not fully conform to ModBus protocol then you might need to directly access RS485 port via serial library.
Reply
#5
At least CRC calculator would be helpful. It has to be implemented in luamodbus. Does it have a public interface?

Or more general question. Is there some kind of 'reflection' available in Lua in case you don't have source codes for included library?
I tried log(require('luamodbus'))
log (require('luamodbus').rtu())
but with no success.
LM5Lp, firmware: 2018.08.22 and 2021.12.15, FlashSYS v2, ARMv7 Processor rev 5 (v7l), kernel 4.4.151 and 4.4.259
Reply
#6
You need to access metatable to get function list:
Code:
function getmetafunctions(object)
  local mt = getmetatable(object)
  local res = {}

  if type(mt) == 'table' then
    for k, v in pairs(mt) do
      if type(v) == 'function' then
        res[ #res + 1 ] = k
      end
    end

    table.sort(res)
  end

  return res
end

obj = require('luamodbus').rtu()
fns = getmetafunctions(obj)
log(fns)

For CRC calculation see this post: https://forum.logicmachine.net/showthread.php?tid=808
Reply
#7
Perfect, thank you!
LM5Lp, firmware: 2018.08.22 and 2021.12.15, FlashSYS v2, ARMv7 Processor rev 5 (v7l), kernel 4.4.151 and 4.4.259
Reply


Forum Jump: