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 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 and 2021.12.15, FlashSYS v2, ARMv7 Processor rev 5 (v7l), kernel 4.4.151 and 4.4.259
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 and 2021.12.15, FlashSYS v2, ARMv7 Processor rev 5 (v7l), kernel 4.4.151 and 4.4.259
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
#11
Hi;

I have a RS232/RS422/RS485 / Modbus converter that allows interfacing a Modbus device with one or more generic serial devices (such as printers, barcode readers, scales, etc.).
Then I need to send a command with several register as  0a 05 a2 04 00 04 af 0b, so the device replays with another several register but the number of byte can be different.

How can I read the response? 

Thanks
Reply
#12
Do you have documentation on this device? The request looks like Modbus but the value that is written is not fully correct.
Reply
#13
The device is not a standard modbus system, so I have to install a gateway to convert the data to standard RS485 modbus. I have to send a special command and the device responds with data. I don't really understand what I have to send to the device and what I have to read out....... I want to use an adfweb converter.
What is this function log(table.concat(buffer))? what data is buffer?
I can use this "mb:writereadregisters(write_reg_start, write_reg_value_1, write_reg_value_2, write_reg_value_3..., read_reg_start, read_reg_count)" to send the correct command but how do I get the response?

Thanks
Reply
#14
buffer is for debugging the serial communication. It's not needed in normal operation.
mb:writereadregisters will return values that are read after writing. The number of values depends on the read_reg_count argument.
Reply
#15
perfect, just I want. Thanks.
Reply


Forum Jump: