Skip to content

Commit f795516

Browse files
Merge pull request #59 from brainelectronics/bugfix/add-missing-issues-template-and-rp2-rtu-usage-examples
Add missing issues template and RP2 RTU usage examples
2 parents 8de96e9 + faeb38f commit f795516

File tree

8 files changed

+206
-8
lines changed

8 files changed

+206
-8
lines changed

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
blank_issues_enabled: false

.github/ISSUE_TEMPLATE/issue.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: "Default issue"
2+
description: Report any kind of issue
3+
body:
4+
- type: textarea
5+
id: description
6+
attributes:
7+
label: Description
8+
description: Please enter an explicit description of your issue
9+
placeholder: Short and explicit description of your incident...
10+
validations:
11+
required: true
12+
- type: textarea
13+
id: reproduction
14+
attributes:
15+
label: Reproduction steps
16+
description: Please enter an explicit description to reproduce this issue
17+
value: |
18+
1.
19+
2.
20+
3.
21+
...
22+
validations:
23+
required: true
24+
- type: input
25+
id: version
26+
attributes:
27+
label: MicroPython version
28+
description: Which MicroPython version are you using?
29+
placeholder: v1.19.1
30+
validations:
31+
required: true
32+
- type: dropdown
33+
id: board
34+
attributes:
35+
label: MicroPython board
36+
description: Which MicroPython board are you using?
37+
options:
38+
- pyboard
39+
- Raspberry Pico
40+
- ESP32
41+
- ESP8266
42+
- WiPy
43+
- i.MXRT
44+
- SAMD21/SAMD51
45+
- Renesas
46+
- Zephyr
47+
- UNIX
48+
- other
49+
validations:
50+
required: true
51+
- type: textarea
52+
id: logs
53+
attributes:
54+
label: Relevant log output
55+
description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks.
56+
render: bash
57+
- type: textarea
58+
id: usercode
59+
attributes:
60+
label: User code
61+
description: Please copy and paste any relevant user code. This will be automatically formatted into Python code, so no need for backticks.
62+
render: python
63+
- type: textarea
64+
id: additional
65+
attributes:
66+
label: Additional informations
67+
description: Please provide additional informations if available
68+
placeholder: Some more informations
69+
validations:
70+
required: false

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ coil_status = host.read_coils(
125125
print('Status of coil {}: {}'.format(coil_status, coil_address))
126126
```
127127

128+
For further details check the latest
129+
[MicroPython Modbus TCP documentation example][ref-latest-tcp-docs-example]
130+
128131
#### RTU
129132

130133
```python
@@ -152,6 +155,9 @@ coil_status = host.read_coils(
152155
print('Status of coil {}: {}'.format(coil_address, coil_status))
153156
```
154157

158+
For further details check the latest
159+
[MicroPython Modbus RTU documentation example][ref-latest-rtu-docs-example]
160+
155161
### Install additional MicroPython packages
156162

157163
To use this package with the provided [`boot.py`][ref-package-boot-file] and
@@ -207,6 +213,8 @@ of this library.
207213
[ref-rtd-micropython-modbus]: https://micropython-modbus.readthedocs.io/en/latest/
208214
[ref-remote-upy-shell]: https://github.com/dhylands/rshell
209215
[ref-examples-folder]: https://github.com/brainelectronics/micropython-modbus/tree/develop/examples
216+
[ref-latest-rtu-docs-example]: https://micropython-modbus.readthedocs.io/en/latest/EXAMPLES.html#rtu
217+
[ref-latest-tcp-docs-example]: https://micropython-modbus.readthedocs.io/en/latest/EXAMPLES.html#tcp
210218
[ref-package-boot-file]: https://github.com/brainelectronics/micropython-modbus/blob/c45d6cc334b4adf0e0ffd9152c8f08724e1902d9/boot.py
211219
[ref-package-main-file]: https://github.com/brainelectronics/micropython-modbus/blob/c45d6cc334b4adf0e0ffd9152c8f08724e1902d9/main.py
212220
[ref-github-be-mircopython-modules]: https://github.com/brainelectronics/micropython-modules

changelog.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
<!-- ## [Unreleased] -->
1616

1717
## Released
18+
## [2.3.3] - 2023-01-29
19+
### Fixed
20+
- Add link to RTU documentation examples from RTU examples files and root [README](README.md), relates to #7
21+
- Add missing ESP32, RP2 and pyboard pin usage for RTU in examples and documentation, relates to #7 and #17
22+
- Add missing issue template file, see #46
23+
1824
## [2.3.2] - 2023-01-09
1925
### Added
2026
- Installation instructions for `mip` usage on MicroPython 1.19.1 or newer, see #44
@@ -260,8 +266,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
260266
- PEP8 style issues on all files of [`lib/uModbus`](lib/uModbus)
261267

262268
<!-- Links -->
263-
[Unreleased]: https://github.com/brainelectronics/micropython-modbus/compare/2.3.2...develop
269+
[Unreleased]: https://github.com/brainelectronics/micropython-modbus/compare/2.3.3...develop
264270

271+
[2.3.3]: https://github.com/brainelectronics/micropython-modbus/tree/2.3.3
265272
[2.3.2]: https://github.com/brainelectronics/micropython-modbus/tree/2.3.2
266273
[2.3.1]: https://github.com/brainelectronics/micropython-modbus/tree/2.3.1
267274
[2.3.0]: https://github.com/brainelectronics/micropython-modbus/tree/2.3.0

docs/EXAMPLES.md

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,22 @@ RTU (serial/UART) to a requesting host device.
2727
from umodbus.serial import ModbusRTU
2828

2929
# RTU Client/Slave setup
30-
# the following example is for an ESP32
30+
31+
# the following definition is for an ESP32
3132
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+
3246
slave_addr = 10 # address on bus as client
3347

3448
client = ModbusRTU(
@@ -39,7 +53,7 @@ client = ModbusRTU(
3953
# stop_bits=1, # optional, default 1
4054
# parity=None, # optional, default None
4155
# 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
4357
)
4458

4559
register_definitions = {
@@ -95,8 +109,21 @@ setting data at a RTU (serial/UART) client/slave.
95109
from umodbus.serial import Serial as ModbusRTUMaster
96110

97111
# RTU Host/Master setup
98-
# the following example is for an ESP32
112+
113+
# the following definition is for an ESP32
99114
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
100127

101128
host = ModbusRTUMaster(
102129
pins=rtu_pins, # given as tuple (TX, RX)
@@ -105,7 +132,7 @@ host = ModbusRTUMaster(
105132
# stop_bits=1, # optional, default 1
106133
# parity=None, # optional, default None
107134
# 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
109136
)
110137

111138
coil_status = host.read_coils(slave_addr=10, starting_addr=123, coil_qty=1)

examples/rtu_client_example.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,52 @@
3737
# check MicroPython UART documentation
3838
# https://docs.micropython.org/en/latest/library/machine.UART.html
3939
# for Device/Port specific setup
40+
#
4041
# RP2 needs "rtu_pins = (Pin(4), Pin(5))" whereas ESP32 can use any pin
41-
# the following example is for an ESP32
42+
# the following example is for an ESP32.
43+
# For further details check the latest MicroPython Modbus RTU documentation
44+
# example https://micropython-modbus.readthedocs.io/en/latest/EXAMPLES.html#rtu
4245
rtu_pins = (25, 26) # (TX, RX)
4346
slave_addr = 10 # address on bus as client
4447
baudrate = 9600
48+
uart_id = 1
49+
50+
try:
51+
from machine import Pin
52+
import os
53+
from umodbus import version
54+
55+
os_info = os.uname()
56+
print('MicroPython infos: {}'.format(os_info))
57+
print('Used micropthon-modbus version: {}'.format(version.__version__))
58+
59+
if 'pyboard' in os_info:
60+
# NOT YET TESTED !
61+
# https://docs.micropython.org/en/latest/library/pyb.UART.html#pyb-uart
62+
# (TX, RX) = (X9, X10) = (PB6, PB7)
63+
uart_id = 1
64+
# (TX, RX)
65+
rtu_pins = (Pin(PB6), Pin(PB7)) # noqa: F821
66+
elif 'esp8266' in os_info:
67+
# https://docs.micropython.org/en/latest/esp8266/quickref.html#uart-serial-bus
68+
raise Exception(
69+
'UART0 of ESP8266 is used by REPL, UART1 can only be used for TX'
70+
)
71+
elif 'esp32' in os_info:
72+
# https://docs.micropython.org/en/latest/esp32/quickref.html#uart-serial-bus
73+
uart_id = 1
74+
rtu_pins = (25, 26) # (TX, RX)
75+
elif 'rp2' in os_info:
76+
# https://docs.micropython.org/en/latest/rp2/quickref.html#uart-serial-bus
77+
uart_id = 0
78+
rtu_pins = (Pin(0), Pin(1)) # (TX, RX)
79+
except AttributeError:
80+
pass
81+
except Exception as e:
82+
raise e
83+
84+
print('Using pins {} with UART ID {}'.format(rtu_pins, uart_id))
85+
4586
client = ModbusRTU(
4687
addr=slave_addr, # address on bus
4788
pins=rtu_pins, # given as tuple (TX, RX)
@@ -50,7 +91,7 @@
5091
# stop_bits=1, # optional, default 1
5192
# parity=None, # optional, default None
5293
# ctrl_pin=12, # optional, control DE/RE
53-
# uart_id=1 # optional, see port specific documentation
94+
uart_id=uart_id # optional, default 1, see port specific docs
5495
)
5596

5697
if IS_DOCKER_MICROPYTHON:

examples/rtu_host_example.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,50 @@
4343
# check MicroPython UART documentation
4444
# https://docs.micropython.org/en/latest/library/machine.UART.html
4545
# for Device/Port specific setup
46+
#
4647
# RP2 needs "rtu_pins = (Pin(4), Pin(5))" whereas ESP32 can use any pin
4748
# the following example is for an ESP32
49+
# For further details check the latest MicroPython Modbus RTU documentation
50+
# example https://micropython-modbus.readthedocs.io/en/latest/EXAMPLES.html#rtu
4851
rtu_pins = (25, 26) # (TX, RX)
4952
baudrate = 9600
53+
uart_id = 1
54+
55+
try:
56+
from machine import Pin
57+
import os
58+
from umodbus import version
59+
60+
os_info = os.uname()
61+
print('MicroPython infos: {}'.format(os_info))
62+
print('Used micropthon-modbus version: {}'.format(version.__version__))
63+
64+
if 'pyboard' in os_info:
65+
# NOT YET TESTED !
66+
# https://docs.micropython.org/en/latest/library/pyb.UART.html#pyb-uart
67+
# (TX, RX) = (X9, X10) = (PB6, PB7)
68+
uart_id = 1
69+
# (TX, RX)
70+
rtu_pins = (Pin(PB6), Pin(PB7)) # noqa: F821
71+
elif 'esp8266' in os_info:
72+
# https://docs.micropython.org/en/latest/esp8266/quickref.html#uart-serial-bus
73+
raise Exception(
74+
'UART0 of ESP8266 is used by REPL, UART1 can only be used for TX'
75+
)
76+
elif 'esp32' in os_info:
77+
# https://docs.micropython.org/en/latest/esp32/quickref.html#uart-serial-bus
78+
uart_id = 1
79+
rtu_pins = (25, 26) # (TX, RX)
80+
elif 'rp2' in os_info:
81+
# https://docs.micropython.org/en/latest/rp2/quickref.html#uart-serial-bus
82+
uart_id = 0
83+
rtu_pins = (Pin(0), Pin(1)) # (TX, RX)
84+
except AttributeError:
85+
pass
86+
except Exception as e:
87+
raise e
88+
89+
print('Using pins {} with UART ID {}'.format(rtu_pins, uart_id))
5090

5191
host = ModbusRTUMaster(
5292
pins=rtu_pins, # given as tuple (TX, RX)
@@ -55,7 +95,7 @@
5595
# stop_bits=1, # optional, default 1
5696
# parity=None, # optional, default None
5797
# ctrl_pin=12, # optional, control DE/RE
58-
# uart_id=1 # optional, see port specific documentation
98+
uart_id=uart_id # optional, default 1, see port specific docs
5999
)
60100

61101
if IS_DOCKER_MICROPYTHON:
@@ -182,6 +222,8 @@
182222
print('Status of IST {}: {}'.format(ist_address, input_status))
183223
time.sleep(1)
184224

225+
print()
226+
185227
# READ IREGS
186228
ireg_address = register_definitions['IREGS']['EXAMPLE_IREG']['register']
187229
register_qty = register_definitions['IREGS']['EXAMPLE_IREG']['len']

examples/tcp_host_example.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@
190190
print('Status of IST {}: {}'.format(ist_address, input_status))
191191
time.sleep(1)
192192

193+
print()
194+
193195
# READ IREGS
194196
ireg_address = register_definitions['IREGS']['EXAMPLE_IREG']['register']
195197
register_qty = register_definitions['IREGS']['EXAMPLE_IREG']['len']

0 commit comments

Comments
 (0)