Skip to content

Modbus Command Set

Modbus mode configuration

There is an RS485 communication interface respectively at the aerial plug of the controller and the aerial plug of the end interface board of the RealMan robotic arm. The two RS485 ports can be configured to standard ModbusRTU mode through the JSON protocol. Then the peripherals connected to the interface can be read or written through the JSON protocol.

Note: The RS485 port of the controller can be used to control the robotic arm when it is not configured to ModbusRTU mode. These two modes are not compatible with each other. To restore the robotic arm control mode, the ModbusRTU mode of the interface must be closed. After the ModbusRTU mode is closed, the system will automatically switch back to the robotic arm control mode, using the baud rate of 460800BPS, stop bit 1, data bit 8, no parity check.

In addition, the Gen 3 controller also supports ModbusTCP master configuration, allowing users to configure the ModbusTCP master to connect the ModbusTCP slaves of external devices.

Set RS485set_RS485

Set the RS485 port baud rate, but there is no return response. Baud rate options: 9600, 19200, 38400, 115200, and 460800. If the user sets a different value, the controller will default to 460800. After issuing this command, if the Modbus mode is enabled, it will automatically be disabled. The controller will then record the current baud rate and continue to use this baud rate for external communication even after a power cycle.

  • Input parameter
ParameterTypeDescription
set_RS485stringSet the RS485 port baud rate, with a maximum of 460800.
  • Code demo

Input

Set the baud rate of the RS485 to 460800.

json
{"command":"set_RS485","baudrate":460800}

Get the controller RS485 mode (Gen 3)get_controller_RS485_mode

  • Input parameter
ParameterTypeDescription
get_controller_RS485_modestringGet the controller RS485 mode.
  • Output parameter
ParameterTypeDescription
controller_RS485_modeint0: RS485 serial communication by default, 1: modbus-RTU master mode, 2: modbus-RTU slave mode.
baudrateintBaud rate.
modbus_timeoutintmodbus protocol timeout period in 100 ms, available only in modbus-RTU mode.
  • Code demo

Input

Get the controller RS485 mode.

json
{"command":"get_controller_RS485_mode"}

Output

json
{
    "command": "get_controller_RS485_mode",
    "controller_RS485_mode": 1,
    "baudrate": 460800,
    "modbus_timeout": 1
}

Get the tool RS485 mode (Gen 3)get_tool_RS485_mode

  • Input parameter
ParameterTypeDescription
get_tool_RS485_modestringGet the tool RS485 mode.
  • Output parameter
ParameterTypeDescription
tool_RS485_modeint0: RS485 serial communication by default, 1: modbus-RTU master mode, 2: modbus-RTU slave mode.
baudrateintBaud rate.
modbus_timeoutintmodbus protocol timeout period in 100 ms, available only in modbus-RTU mode.
  • Code demo

Input

Get the tool RS485 mode.

json
{"command":"get_tool_RS485_mode"}

Output

json
{
    "command": "get_tool_RS485_mode",
    "tool_RS485_mode": 0,
    "baudrate": 460800,
    "modbus_timeout": 1
}

Set ModbusRTU mode of communication portset_modbus_mode

Set the ModbusRTU mode of communication port. After the robotic arm is started, this command must be initiated first for any operation on the communication port; otherwise, error information will be returned.

  • Input parameter
ParameterTypeDescription
set_modbus_modestringSet ModbusRTU mode of communication port.
portintCommunication port, 0: controller RS485 port as RTU master, 1: end interface board RS485 port as RTU master, 2: controller RS485 port as RTU slave.
baudrateintBaud rate, supporting three common baud rates, namely 9600, 115200, and 460800.
timeoutintTimeout period, in 100 ms. For all read and write commands to the Modbus device, if no response data is returned within the specified timeout period, a timeout error will be returned. The timeout period cannot be set to 0; if set to 0, the robotic arm will take it as 1 for configuration.
  • Code demo

Input

json
{"command":"set_modbus_mode","port":0,"baudrate":115200,"timeout":1}

Output Setting succeeded

json
{
    "command": "set_modbus_mode",
    "set_state": true
}

Setting failed

json
{
    "command": "set_modbus_mode",
    "set_state": false
}

Close ModbusRTU mode of communication portclose_modbus_mode

  • Input parameter
ParameterTypeDescription
close_modbus_modestringClose ModbusRTU mode of communication port.
portintCommunication port, 0: controller RS485 port as RTU master, 1: end interface board RS485 port as RTU master, 2: controller RS485 port as RTU slave.
  • Code demo

Input

json
{"command":"close_modbus_mode","port":0}

Output Setting succeeded:

json
{
    "command": "close_modbus_mode",
    "set_state": true
}

Setting failed:

json
{
    "command": "close_modbus_mode",
    "set_state": false
}

Set to connect to ModbusTCP slave (Gen 3 controller)rm_set_modbustcp_mode()

The controller acts as a ModbusTCP master to connect to external ModbusTCP slave devices.

  • Input parameter
ParameterTypeDescription
set_modbustcp_modestringConnect to ModbusTCP slave.
ipstringSlave IP address.
portintCommunication port number.
timeoutintTimeout period, in ms.
  • Code demo

Input

json
{"command":"set_modbustcp_mode","ip":"192.168.1.120","port":502,"timeout":2000}

Output Connection succeeded:

json
{
    "command": "set_modbustcp_mode",
    "set_state": true
}

Connection failed:

json
{
    "command": "set_modbustcp_mode",
    "set_state": false
}

Close ModbusTCP slave (Gen 3 controller)close_modbustcp_mode

  • Input parameter
ParameterTypeDescription
close_modbustcp_modestringDisconnect to ModbusTCP slave.
  • Code demo

Input

json
{"command":"close_modbustcp_mode"}

Output Success:

json
{
    "command": "close_modbustcp_mode",
    "set_state": true
}

Fail:

json
{
    "command": "close_modbustcp_mode",
    "set_state": false
}

Modbus protocol command

Read coilsread_coils

  • Input parameter
ParameterTypeDescription
read_coilsstringRead coils.
portintCommunication port, 0: controller RS485 port, 1: end interface board RS485 port, 3: controller ModbusTCP port for connecting to external slave devices.
addressintCoil starting address.
numintNumber of coils to read. This command can read up to 8 coils once, that is, the returned data will not be longer than one byte.
deviceintPeripheral device address.
  • Code demo

Input

json
{"command":"read_coils","port":0,"address":10,"num":2,"device":2}

Output Reading succeeded, returning coil state, data type: int8.

json
{
    "command": "read_coils",
    "data": 8
}

Reading failed, no data received within the timeout period.

json
{
    "command": "read_coils",
    "read_state": false
}

Read multiple coilsread_multiple_coils

  • Input parameter
ParameterTypeDescription
read_multiple_coilsstringRead multiple coils.
portintCommunication port, 0: controller RS485 port, 1: end interface board RS485 port, 3: controller ModbusTCP port for connecting to external slave devices.
addressintCoil starting address.
numint8 ≤ num ≤ 120 represents the number of wire coils to be read. This command supports reading up to 120 coils at a time, which is equivalent to 15 bytes.
deviceintPeripheral Device Address.
  • Code demo

Input

json
{"command":"read_multiple_coils","port":0,"address":0,"num":24,"device":2}

Output Reading succeeded, returning coil state, data type: int8.

json
{
    "command": "read_multiple_coils",
    "data": [
        1,
        2,
        3
    ]
}

Reading failed, no data received within the timeout period.

json
{
    "command": "read_multiple_coils",
    "read_state": false
}

Write single coil datawrite_single_coil

  • Input parameter
ParameterTypeDescription
write_single_coilstringWrite single coil data.
portintCommunication port, 0: controller RS485 port, 1: end interface board RS485 port, 3: controller ModbusTCP port for connecting to external slave devices.
addressintCoil starting address.
dataintData to be written to the coil, data type: int16.
deviceintPeripheral device address.
  • Code demo

Input

json
{"command":"write_single_coil","port":0,"address":10,"data":1,"device":2}

Output

Writing succeeded.

json
{
    "command": "write_single_coil",
    "write_state": true
}

Writing failed, no data received within the timeout period or an error occurred in the command content.

json
{
    "command": "write_single_coil",
    "write_state": false
}

Write multi-coil datawrite_coils

  • Input parameter
ParameterTypeDescription
write_coilsstringWrite multi-coil data.
portintCommunication port, 0: controller RS485 port, 1: end interface board RS485 port, 3: controller ModbusTCP port for connecting to external slave devices.
addressintCoil starting address.
numintNumber of coils to write, with the quantity written each time not exceeding 160.
dataintThe data group to be written to the coils, type: byte. If the number of coils is not greater than 8, the data to be written is one byte; otherwise, it is an array of multiple data.
deviceintPeripheral device address.
  • Code demo

Input

json
{"command":"write_coils","port":0,"address":10,"num":16,"data":[15,20],"device":2}

Output Writing succeeded.

json
{
    "command": "write_coils",
    "write_state": true
}

Writing failed, no data received within the timeout period or an error occurred in the command content.

json
{
    "command": "write_coils",
    "write_state": false
}

Read discrete inputsread_input_status

  • Input parameter
ParameterTypeDescription
read_input_statusstringRead discrete inputs.
portintCommunication port, 0: controller RS485 port, 1: end interface board RS485 port, 3: controller ModbusTCP port for connecting to external slave devices.
addressintCoil starting address.
numintNumber of data to read. This command can read up to 8 discrete datas once, that is, the returned data will not be longer than one byte.
deviceintPeripheral device address.
  • Code demo

Input

json
{
    "command": "read_input_status",
    "port": 0,
    "address": 10,
    "num": 2,
    "device": 2
}

Output Reading succeeded, returning discrete magnitude, data type: int8.

json
{
    "command": "read_input_status",
    "data": 8
}

Reading failed, no data received within the timeout period.

json
{
    "command": "read_input_status",
    "read_state": false
}

Read holding registerread_holding_registers

  • Input parameter
ParameterTypeDescription
read_holding_registersstringRead holding register.
portintCommunication port, 0: controller RS485 port, 1: end interface board RS485 port, 3: controller ModbusTCP port for connecting to external slave devices.
addressintData starting address, this command can only read one register at a time, which is 2 bytes of data, and cannot read data from multiple registers at once.
deviceintPeripheral device address.
  • Code demo

Input

json
{"command":"read_holding_registers","port":0,"address":10,"device":2}

Output Reading succeeded, returning register data, data type: int16.

json
{
    "command": "read_holding_registers",
    "data": 16
}

Reading failed, no data received within the timeout period.

json
{
    "command": "read_holding_registers",
    "read_state": false
}

Write single registerwrite_single_register

  • Input parameter
ParameterTypeDescription
write_single_registerstringWrite single register.
portintCommunication port, 0: controller RS485 port, 1: end interface board RS485 port, 3: controller ModbusTCP port for connecting to external slave devices.
addressintRegister starting address.
dataintData to be written to the Register, data type: int16.
deviceintPeripheral device address.
  • Code demo

Input

json
{"command":"write_single_register","port":0,"address":10,"data":1000,"device":2}

Output Writing succeeded.

json
{
    "command": "write_single_register",
    "write_state": true
}

Writing failed, no data received within the timeout period or an error occurred in the command content.

json
{
    "command": "write_single_register",
    "write_state": false
}

Write multiple registerswrite_registers

  • Input parameter
ParameterTypeDescription
write_registersstringWrite multiple registers.
portintCommunication port, 0: controller RS485 port, 1: end interface board RS485 port, 3: controller ModbusTCP port for connecting to external slave devices.
addressintCoil starting address.
numintNumber of registers to write. This command can write up to 10 registers once.
dataintData to be written to the coil, data type: int16.
deviceintPeripheral device address.
  • Code demo

Input

json
{"command":"write_registers","port":0,"address":10,"num":2,"data":[15,20,25,30],"device":2}

Output Writing succeeded.

json
{
    "command": "write_registers",
    "write_state": true
}

Writing failed, no data received within the timeout period or an error occurred in the command content.

json
{
    "command": "write_registers",
    "write_state": false
}

Read multiple holding registersread_multiple_holding_registers

  • Input parameter
ParameterTypeDescription
read_multiple_holding_registersstringRead multiple holding registers.
portintCommunication port, 0: controller RS485 port, 1: end interface board RS485 port, 3: controller ModbusTCP port for connecting to external slave devices.
addressintRegisters starting address.
numintThe number of registers to read is 2 < num ≤ 13. This command can read up to 12 registers once, that is, 24 bytes.
deviceintPeripheral device address.
  • Code demo

Input

json
{"command":"read_multiple_holding_registers","port":0,"address":0,"num":5,"device":2}

Output Reading succeeded, returning register data, data type: int8.

json
{
    "command": "read_multiple_holding_registers",
    "data": [
        1,
        2,
        3,
        4,
        5,
        6,
        7,
        8,
        9,
        10
    ]
}

Reading failed, no data received within the timeout period.

json
{
    "command": "read_multiple_holding_registers",
    "read_state": false
}

Read input registerread_input_registers

  • Input parameter
ParameterTypeDescription
read_input_registersstringRead input register.
portintCommunication port, 0: controller RS485 port, 1: end interface board RS485 port, 3: controller ModbusTCP port for connecting to external slave devices.
addressintCoil starting address.
deviceintPeripheral device address.
  • Code demo

Input

json
{"command":"read_input_registers","port":0,"address":10,"device":2}

Output Reading succeeded, returning register data, data type: int16.

json
{
    "command": "read_input_registers",
    "data": 8
}

Reading failed, no data received within the timeout period.

json
{
    "command": "read_input_registers",
    "read_state": false
}

Read multiple input registersread_multiple_input_registers

  • Input parameter
ParameterTypeDescription
read_multiple_input_registersstringRead multiple input registers.
portintCommunication port, 0: controller RS485 port, 1: end interface board RS485 port, 3: controller ModbusTCP port for connecting to external slave devices.
addressintCoil starting address.
numintThe number of registers to read is 2 < num < 13. This command can read up to 12 registers once, that is, 24 bytes.
deviceintPeripheral device address.
  • Code demo

Input

json
{"command":"read_multiple_input_registers","port":0,"address":0,"num":5,"device":2}

Output Reading succeeded, returning register data, data type: int8.

json
{
    "command": "read_multiple_input_registers",
    "data": [
        1,
        2,
        3,
        4,
        5,
        6,
        7,
        8,
        9,
        10
    ]
}

Reading failed, no data received within the timeout period.

json
{
    "command": "read_multiple_input_registers",
    "read_state": false
}