Logic Machine Forum
luamodbus - 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: luamodbus (/showthread.php?tid=2018)



luamodbus - Thomas - 10.04.2019

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?


RE: luamodbus - admin - 10.04.2019

What functions do you need? Most cases are handled by profiles so direct ModBus access is not needed.


RE: luamodbus - Thomas - 10.04.2019

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.


RE: luamodbus - admin - 10.04.2019

If the device does not fully conform to ModBus protocol then you might need to directly access RS485 port via serial library.


RE: luamodbus - Thomas - 10.04.2019

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.


RE: luamodbus - admin - 11.04.2019

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


RE: luamodbus - Thomas - 11.04.2019

Perfect, thank you!