Skip to content

Commit ad7741c

Browse files
add RTU usage example to docs, contributes to brainelectronics#7, brainelectronics#17 and brainelectronics#43
1 parent f20e4f1 commit ad7741c

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

docs/USAGE.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ based on TCP togehter with the latest provided
241241
All described functions require a successful setup of a Host communicating
242242
to/with a Client device which is providing the data and accepting the new data.
243243

244+
#### TCP
245+
244246
```python
245247
from umodbus.tcp import TCP as ModbusTCPMaster
246248

@@ -254,6 +256,31 @@ host = ModbusTCPMaster(
254256
timeout=5) # optional, default 5
255257
```
256258

259+
#### RTU
260+
261+
```python
262+
from umodbus.serial import Serial as ModbusRTUMaster
263+
264+
slave_addr = 10 # bus address of client
265+
266+
# check MicroPython UART documentation
267+
# https://docs.micropython.org/en/latest/library/machine.UART.html
268+
# for Device/Port specific setup
269+
# RP2 needs "rtu_pins = (Pin(4), Pin(5))" whereas ESP32 can use any pin
270+
# the following example is for an ESP32
271+
rtu_pins = (25, 26) # (TX, RX)
272+
host = ModbusRTUMaster(
273+
addr=1, # bus address of this Host/Master, usually '1'
274+
baudrate=9600, # optional, default 9600
275+
pins=rtu_pins, # given as tuple (TX, RX)
276+
# data_bits=8, # optional, default 8
277+
# stop_bits=1, # optional, default 1
278+
# parity=None, # optional, default None
279+
# ctrl_pin=12, # optional, control DE/RE
280+
# uart_id=1 # optional, see port specific documentation
281+
)
282+
```
283+
257284
#### Coils
258285

259286
Coils represent binary states, which can be get as and set to either `0` (off)

0 commit comments

Comments
 (0)