Elibot support both ModBus Master and slave function. Elibot can use Modbus TCP and Modbus RTU.
Robot can read/ write device data through Modbus master.
To use Modbus TCP, user need to connect lan wire to device/hub through robot controller etherner port;
to use Modbus RTU, user can use RS485 port on robot controller and RS485 port on robot flange.
User need to use LUA script(instruction can be refered in Elibot Lua manual) to achieve Modbus function.
ctx = modbus_new_rtu(choose, baud, parity, data_bit, stop_bit)
Parameter: choose: 0-serial port on core board; 2-serial port on flange IO
Baud: baud rate (up to 460800 for port on core board and 9600 for port on flange IO),
default 4800 if not defined.
Parity: ASCII code of “E”(69),”N”(78) or “O”(79). Default 78 if not defined.
Data_bit: 7/8. Default 8 if not defined.
Sto_bit:1/2. Default 1 if not defined.
Return: ctx-modbus handle
Note: This command is applicable to v2.9.3 and above.
example:
ctx = modbus_new_rtu(2, 9600, 78, 8, 1)
ctx = modbus_new_tcp(ip, port)
Parameter: IP: IP address of Modbus slave
Port: port number of Modbus slave
Return: ctx-modbus handle
example:
ctx = modbus_new_tcp("192.168.1.15", 502)
ret = modbus_connect(ctx)
Parameter: ctx created by modbus_new_rtu or modbus_new_tcp
Return: if TCP connection is failed to be established, return -1. Otherwise, returns any positive integer. (Fot TCP connection only, cannot be used to evaluate RTU connection.)
example:
modbus_connect(ctx)
modbus_close(ctx)
Parameter: ctx created by modbus_new_rtu or modbus_new_tcp
Return: None
example:
modbus_close(ctx)
ret = modbus_set_slave(ctx, slave_id)
Parameter: ctx: ctx created by modbus_new_rtu or modbus_new_tcp
slave_id: slave address
Return: if set failed, returns -1. Otherwise, returns any positive integer.
example:
modbus_set_slave(ctx ,0x2)
ret = modbus_write_register(ctx, reg, value)
Parameter: ctx: ctx created by modbus_new_rtu or modbus_new_tcp
reg: register address (in decimal)
value: data to be written
Return: if write failed, returns -1. Otherwise, returns any positive integer.
example:
modbus_write_register(ctx , 771, 1)
reg_value = modbus_read_bits(ctx, reg, len)
Parameter: ctx: ctx created by modbus_new_rtu or modbus_new_tcp
reg: coli adress
len: number of coils(<128)
Return: ret