Logic Machine Forum
luamodbus documentation - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Gateway (https://forum.logicmachine.net/forumdisplay.php?fid=10)
+--- Thread: luamodbus documentation (/showthread.php?tid=1225)



luamodbus documentation - hummelsystemhaus - 07.02.2018

hi everyone, i havent found anything yet so:
is there a full documentation for the luamodbus libery we are using here?


RE: luamodbus documentation - admin - 13.02.2018

There's no full documentation right now, are you looking for some specific functions?


RE: luamodbus documentation - hummelsystemhaus - 15.02.2018

(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?


RE: luamodbus documentation - admin - 15.02.2018

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?


RE: luamodbus documentation - hummelsystemhaus - 16.02.2018

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?


RE: luamodbus documentation - admin - 16.02.2018

No, only one id can be set for each slave instance.


RE: luamodbus documentation - Thomas - 20.06.2019

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


RE: luamodbus documentation - admin - 20.06.2019

By standard response to write request contains exactly the same data. So any Luamodbus write function returns just true/false.


RE: luamodbus documentation - Thomas - 21.06.2019

(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


RE: luamodbus documentation - admin - 21.06.2019

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)



RE: luamodbus documentation - AngelesTR - 10.01.2023

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


RE: luamodbus documentation - admin - 11.01.2023

Do you have documentation on this device? The request looks like Modbus but the value that is written is not fully correct.


RE: luamodbus documentation - AngelesTR - 11.01.2023

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


RE: luamodbus documentation - admin - 11.01.2023

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.


RE: luamodbus documentation - AngelesTR - 11.01.2023

perfect, just I want. Thanks.