Skip to main content
Version: 1.0

Modbus RTU Client

The Modbus RTU Client is exposed as an MbRtuClient component when a Serial instance is configured in mb_client mode.

All methods on this page require id, which identifies the MbRtuClient component instance.

Available methods:

Methods

MbRtuClient.GetConfig

Properties:

PropertyTypeDescription

id

number

MbRtuClient component instance id

Find the MbRtuClient.GetConfig response properties in Configuration

MbRtuClient.SetConfig

Properties:

PropertyTypeDescription

id

number

MbRtuClient component instance id

config

object

Configuration to apply

MbRtuClient.GetStatus

Properties:

PropertyTypeDescription

id

number

MbRtuClient component instance id

Find the MbRtuClient.GetStatus response properties in Status

MbRtuClient.ReadHoldingRegisters

Read Holding Registers (function code 0x03).

Properties:

PropertyTypeDescription

id

number

MbRtuClient component instance id

sid

number

Modbus server id, 1 to 247

addr

number

Start register address (0 to 65535)

qty

number

Number of registers to read, 1 to 123

Response:

PropertyTypeDescription

values

array of numbers

Array of 16-bit unsigned register values

MbRtuClient.ReadInputRegisters

Read Input Registers (function code 0x04).

Properties:

PropertyTypeDescription

id

number

MbRtuClient component instance id

sid

number

Modbus server id, 1 to 247

addr

number

Start register address (0 to 65535)

qty

number

Number of registers to read, 1 to 123

Response:

PropertyTypeDescription

values

array of numbers

Array of 16-bit unsigned register values

MbRtuClient.ReadDiscreteInputs

Read Discrete Inputs (function code 0x02).

Properties:

PropertyTypeDescription

id

number

MbRtuClient component instance id

sid

number

Modbus server id, 1 to 247

addr

number

Start bit address (0 to 65535)

qty

number

Number of bits to read, 1 to 2000

Response:

PropertyTypeDescription

values

array of booleans

Array of input values

MbRtuClient.ReadCoils

Read Coils (function code 0x01).

Properties:

PropertyTypeDescription

id

number

MbRtuClient component instance id

sid

number

Modbus server id, 1 to 247

addr

number

Start bit address (0 to 65535)

qty

number

Number of bits to read, 1 to 2000

Response:

PropertyTypeDescription

values

array of booleans

Array of coil values

MbRtuClient.WriteHoldingRegisters

Write Multiple Holding Registers (function code 0x10).

Properties:

PropertyTypeDescription

id

number

MbRtuClient component instance id

sid

number

Modbus server id, 1 to 247

addr

number

Start register address (0 to 65535)

values

array of numbers

Array of 16-bit unsigned values, 1 to 123 items

Return:

This method returns status only.

MbRtuClient.WriteSingleRegister

Write a single Holding Register (function code 0x06).

Properties:

PropertyTypeDescription

id

number

MbRtuClient component instance id

sid

number

Modbus server id, 1 to 247

addr

number

Register address (0 to 65535)

value

number

16-bit unsigned value (0 to 65535)

Return:

This method returns status only.

MbRtuClient.WriteCoils

Write Multiple Coils (function code 0x0F).

Properties:

PropertyTypeDescription

id

number

MbRtuClient component instance id

sid

number

Modbus server id, 1 to 247

addr

number

Start bit address (0 to 65535)

values

array of booleans

Array of coil values, 1 to 2000 items

Return:

This method returns status only.

Configuration

At the moment, MbRtuClient has no configurable properties.

Status

At the moment, MbRtuClient has no status properties.

Examples

MbRtuClient.ReadHoldingRegisters example

http://192.168.33.1/rpc/MbRtuClient.ReadHoldingRegisters?id=0&sid=1&addr=100&qty=2

Response

{
"values": [
230,
231
]
}

MbRtuClient.ReadInputRegisters example

http://192.168.33.1/rpc/MbRtuClient.ReadInputRegisters?id=0&sid=1&addr=300&qty=3

Response

{
"values": [
1123,
1127,
1131
]
}

MbRtuClient.ReadDiscreteInputs example

http://192.168.33.1/rpc/MbRtuClient.ReadDiscreteInputs?id=0&sid=2&addr=0&qty=4

Response

{
"values": [
true,
false,
false,
true
]
}

MbRtuClient.ReadCoils example

http://192.168.33.1/rpc/MbRtuClient.ReadCoils?id=0&sid=2&addr=10&qty=5

Response

{
"values": [
false,
true,
true,
false,
false
]
}

MbRtuClient.WriteHoldingRegisters example

http://192.168.33.1/rpc/MbRtuClient.WriteHoldingRegisters?id=0&sid=3&addr=400&values=[1000,2000]

Response

{}

MbRtuClient.WriteSingleRegister example

http://192.168.33.1/rpc/MbRtuClient.WriteSingleRegister?id=0&sid=3&addr=402&value=1234

Response

{}

MbRtuClient.WriteCoils example

http://192.168.33.1/rpc/MbRtuClient.WriteCoils?id=0&sid=4&addr=0&values=[true,true,false,true]

Response

{}

MbRtuClient.GetConfig example

http://192.168.33.1/rpc/MbRtuClient.GetConfig?id=0

Response

{}

MbRtuClient.SetConfig example

http://192.168.33.1/rpc/MbRtuClient.SetConfig?id=0&config={}

Response

{
"restart_required": false
}

MbRtuClient.GetStatus example

http://192.168.33.1/rpc/MbRtuClient.GetStatus?id=0

Response

{}