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 whether you accept or reject these cookies being set.

luamodbus documentation
#1
hi everyone, i havent found anything yet so:
is there a full documentation for the luamodbus libery we are using here?
Reply
#2
There's no full documentation right now, are you looking for some specific functions?
Reply
#3
(13.02.2018, 11:23)admin Wrote: There's no full documentation right now, are you looking for some specific functions?

yeah, i would like to know if its possible it be a Modbus TCP slave (yes its possible) but with more than one slave id.

so i will provide for example 10 diffrent modbus devices with diffrent slave ids and diffrent register mappings. is this possible?
Reply
#4
That's not possible to do from a single script. You can use different script for each slave and different TCP ports. Does your master device support non-default TCP ports for slaves?
Reply
#5
i think thats not a nice solution. There isnt a defined Master Device. it would be nice to make one TCP "Slave" and handle alle requests.

isnt it possible the get the requested slave id in the "handle request function" or some thing like that?
Reply
#6
No, only one id can be set for each slave instance.
Reply
#7
Hi
Can you send me a short description of writereadregisters function please?
What I'm looking for is: My device returns actual state after every write. I think this function writes a value to a register and waits for reply from the same register. But I'm not sure how to use ti.
Thank you
LM5Lp, firmware: 2018.08.22, FlashSYS v2, ARMv7 Processor rev 5 (v7l), kernel 4.4.151





Reply
#8
By standard response to write request contains exactly the same data. So any Luamodbus write function returns just true/false.
Reply
#9
(20.06.2019, 16:59)admin Wrote: By standard response to write request contains exactly the same data. So any Luamodbus write function returns just true/false.

Does really readregister wait for this reply and read full answer? Not only number of bytes that were sent?
Because if I do this:
Code:
for index, value in ipairs(self.modbus_mapping) do
           local val,err=self.mb_aolan:writeregisters(value.register,write_val)
           if (val == nil) then
              -- here I do something with the error
             return
           end
         --os.sleep(0.1)
         os.sleep(0.05)
end
then with os.sleep lower than 0.05 I get err from the next write. Maybe it's error on the slave side but my first idea was I'm getting this error because I'm too fast and the counterpart is still sending data.

Can you please send me list of parameters for writereadregisters?

Thank you
LM5Lp, firmware: 2018.08.22, FlashSYS v2, ARMv7 Processor rev 5 (v7l), kernel 4.4.151





Reply
#10
You can enable debug mode to see what data is sent/received:
Code:
require('luamodbus')

buffer = {}

function logger(c)
table.insert(buffer, c)
end

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

-- read/write here

log(table.concat(buffer))

You can also add mb:flush() after sleep to discard any invalid data that could be received.

Code:
mb:writereadregisters(write_reg_start, write_reg_value_1, write_reg_value_2, write_reg_value_3..., read_reg_start, read_reg_count)
Reply


Forum Jump: