---
title: Modbus
slug: modbus
docTags: 
createdAt: 2023-10-03T11:49:03.771Z
---

Modbus command can be used to communicate with other devices over Modbus protocol.

Please note that your controller board needs to have the Modbus feature and that the controller board has to be the master device.

:::BlockQuote
ModBus \<s> \<f> \<a> \<n> \<v> \<u> \<b> \<fb> \<t> \<o>
:::

### Parameters

- **s** defines the slave number.
- **f&#x20;**&#x66;unction number
- **a&#x20;**&#x61;ddress
- **n** number of bits or registers
- **v** value
- **u** user variable
- **b&#x20;**&#x62;aud rate
  - If not specified, baud rate of 115200 is used
- **fb** parity / stop bits configuration designation
  - If not specified, no parity and 2 stop bits are used
- **t** data type used in RMR/3 and WMR/16
- **o** the data ordering used in RMR/3 and WMR/16

### Supported baud rates

- 9600
- 19200
- 38400
- 57600
- 76800
- 115200

### Supported function numbers

|    |      |                               |
| -- | ---- | ----------------------------- |
| 1  | RMC  | Read Multiple Coils           |
| 2  | RDI  | Read Discrete Inputs          |
| 3  | RMR  | Read Multiple Registers       |
| 4  | RMIR | Read Multiple Input Registers |
| 5  | WSI  | Write Single Coil             |
| 6  | WSR  | Write Single Registers        |
| 15 | WMC  | Write Multiple Coils          |
| 16 | WMR  | Write Multiple Registers      |
| 17 | RS   | Report SlaveID                |

The abbreviation can be used instead of the number, so `F=RMC` or `F RMC` is
equal to `F1`

### Parity / stop bits configuration designations

| Setting | Parity | Stop bits |
| ------- | ------ | --------- |
| E1      | even   | 1         |
| O1      | odd    | 1         |
| N2      | none   | 2         |
| N1      | none   | 1         |

### Data type designations (introduced in version 5.3)

| Value | Type information                  |
| ----- | --------------------------------- |
| u16   | 16-bit unsigned integer (default) |
| u32   | 32-bit unsigned integer           |
| u64   | 64-bit unsigned integer           |
| i16   | 16-bit signed integer             |
| i32   | 32-bit signed integer             |
| i64   | 64-bit signed integer             |
| d32   | 32-bit floating point number      |
| d64   | 64-bit floating point number      |

### Data ordering designation (introduced in version 5.3)

| Value | Ordering information                                            |
| ----- | --------------------------------------------------------------- |
| n     | No reordering of data (default)                                 |
| b     | Swap the bytes within each register(16-bits)                    |
| w     | Swap the placement of each register used in the combined value  |
| bw    | Swap both the register placement and the bytes in each register |

### Example

Write single coil

:::BlockQuote
Modbus s1 f5 a0 v1
:::

Write single coil, baud rate of 19200, even parity with 1 stop bit

:::BlockQuote
Modbus s1 f5 a0 v1 b19200 fb=e1
:::

Read multiple coils, store beginning at user variable #300

:::BlockQuote
modbus s1 f=rmc a0 n8 u300&#x20;
msg "c0="#300 " c1="#301 " c2="#302 " c3="#303 " c4="#304 " c5="#305 " c6="#306 " c7="#307
:::

Read discrete inputs

:::BlockQuote
modbus s1 f=rdi a0 n8 u400&#x20;
msg "i0="#400 " i1="#401 " i2="#402 " i3="#403 " i4="#404 " i5="#405 " i6="#406 " i7="#407
:::

Write single register

:::BlockQuote
modbus s1 f6 a0 v255
:::

Write multiple coils

:::BlockQuote
\#500=0
\#501=1
\#502=0
\#503=1
\#504=0
\#505=1
\#506=0
\#507=1
modbus s1 f15 a0 n8 u500
:::

Write multiple holding registers

:::BlockQuote
\#600 = 1
\#601 = 2
modbus s1 f16 a0 n2 u600
:::

Report slave id

:::BlockQuote
modbus s1 f17
:::

Read a double value (64-bit floating point) from a slave device with no data reordering. (introduced in version 5.3)

:::BlockQuote
modbus s1 f3 a0 n1 u700 t=d64 o=n
:::

