Modbus
After adding Modbus devices in the UI interface, you can communicate with Modbus devices
Set Timeout
lebai:set_modbus_timeout(device, timeout)
- Parameters
device
Device nametimeout
Timeout duration in milliseconds (ms). Default 600ms
Set Timeout Retransmissions
lebai:set_modbus_retry(device, retry)
- Parameters
device
Device nameretry
Number of timeout retransmissions. Default is 0.
Write Single Coil
lebai:write_single_coil(device, addr, value)
- Parameters
device
Device nameaddr
Register addressvalue
Value to set
Write Multiple Coils
lebai:write_multiple_coils(device, addr, values)
- Parameters
device
Device nameaddr
Register addressvalues
Values to set
Read Coils
values = lebai:read_coils(device, addr, num)
- Parameters
device
Device nameaddr
Register addressnum
Consecutive quantity
Read Discrete Inputs
values = lebai:read_discrete_inputs(device, addr, num)
- Parameters
device
Device nameaddr
Register addressnum
Consecutive quantity
Write Single Register
lebai:write_single_register(device, addr, value)
- Parameters
device
Device nameaddr
Register addressvalue
Value to set
Write Multiple Registers
lebai:write_multiple_registers(device, addr, values)
- Parameters
device
Device nameaddr
Register addressvalues
Values to set
Read Holding Registers
values = lebai:read_holding_registers(device, addr, num)
- Parameters
device
Device nameaddr
Register addressnum
Consecutive quantity
Read Input Registers
values = lebai:read_input_registers(device, addr, num)
- Parameters
device
Device nameaddr
Register addressnum
Consecutive quantity
Example
local device = "/dev/ttyS1"
lebai:set_serial_timeout(device, 200)
lebai:set_serial_baud_rate(device, 9600)
lebai:set_modbus_timeout("485_1", 500)
lebai:write_single_coil("485_1", "100", false)