@@ -27,8 +27,22 @@ RTU (serial/UART) to a requesting host device.
27
27
from umodbus.serial import ModbusRTU
28
28
29
29
# RTU Client/Slave setup
30
- # the following example is for an ESP32
30
+
31
+ # the following definition is for an ESP32
31
32
rtu_pins = (25 , 26 ) # (TX, RX)
33
+ uart_id = 1
34
+
35
+ # the following definition is for a RP2
36
+ # rtu_pins = (Pin(0), Pin(1)) # (TX, RX)
37
+ # uart_id = 0
38
+ #
39
+ # rtu_pins = (Pin(4), Pin(5)) # (TX, RX)
40
+ # uart_id = 1
41
+
42
+ # the following definition is for a pyboard
43
+ # rtu_pins = (Pin(PB6), Pin(PB7)) # (TX, RX)
44
+ # uart_id = 1
45
+
32
46
slave_addr = 10 # address on bus as client
33
47
34
48
client = ModbusRTU(
@@ -39,7 +53,7 @@ client = ModbusRTU(
39
53
# stop_bits=1, # optional, default 1
40
54
# parity=None, # optional, default None
41
55
# ctrl_pin=12, # optional, control DE/RE
42
- # uart_id=1 # optional, see port specific documentation
56
+ uart_id = uart_id # optional, default 1 , see port specific documentation
43
57
)
44
58
45
59
register_definitions = {
@@ -95,8 +109,21 @@ setting data at a RTU (serial/UART) client/slave.
95
109
from umodbus.serial import Serial as ModbusRTUMaster
96
110
97
111
# RTU Host/Master setup
98
- # the following example is for an ESP32
112
+
113
+ # the following definition is for an ESP32
99
114
rtu_pins = (25 , 26 ) # (TX, RX)
115
+ uart_id = 1
116
+
117
+ # the following definition is for a RP2
118
+ # rtu_pins = (Pin(0), Pin(1)) # (TX, RX)
119
+ # uart_id = 0
120
+ #
121
+ # rtu_pins = (Pin(4), Pin(5)) # (TX, RX)
122
+ # uart_id = 1
123
+
124
+ # the following definition is for a pyboard
125
+ # rtu_pins = (Pin(PB6), Pin(PB7)) # (TX, RX)
126
+ # uart_id = 1
100
127
101
128
host = ModbusRTUMaster(
102
129
pins = rtu_pins, # given as tuple (TX, RX)
@@ -105,7 +132,7 @@ host = ModbusRTUMaster(
105
132
# stop_bits=1, # optional, default 1
106
133
# parity=None, # optional, default None
107
134
# ctrl_pin=12, # optional, control DE/RE
108
- # uart_id=1 # optional, see port specific documentation
135
+ uart_id = uart_id # optional, default 1 , see port specific documentation
109
136
)
110
137
111
138
coil_status = host.read_coils(slave_addr = 10 , starting_addr = 123 , coil_qty = 1 )
0 commit comments