Skip to content

Commit b7059ae

Browse files
Merge c36d586 into 4699684
2 parents 4699684 + c36d586 commit b7059ae

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

changelog.md

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

1717
## Released
18+
## [2.1.2] - 2022-12-28
19+
### Changed
20+
- Baudrate specific inter frame time is used at Modbus RTU internal function `_uart_read` of [serial.py](umodbus/serial.py) instead of constant value of 5ms
21+
22+
### Fixed
23+
- ESP32 port specific `wait_tx_done` function replaced by generic wait time calculation in `_send` function of [serial.py](umodbus/serial.py), see #34
24+
- A 1ms delay has been added between turning the RS485 control pin on and sending the Modbus PDU in `_send` function of [serial.py](umodbus/serial.py)
25+
1826
## [2.1.1] - 2022-12-27
1927
### Fixed
2028
- Removed unnecessary dependency to `micropython-urequests` from Docker files, setup guide and package setup file
@@ -182,8 +190,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
182190
- PEP8 style issues on all files of [`lib/uModbus`](lib/uModbus)
183191

184192
<!-- Links -->
185-
[Unreleased]: https://github.com/brainelectronics/micropython-modbus/compare/2.1.1...develop
193+
[Unreleased]: https://github.com/brainelectronics/micropython-modbus/compare/2.1.2...develop
186194

195+
[2.1.2]: https://github.com/brainelectronics/micropython-modbus/tree/2.1.2
187196
[2.1.1]: https://github.com/brainelectronics/micropython-modbus/tree/2.1.1
188197
[2.1.0]: https://github.com/brainelectronics/micropython-modbus/tree/2.1.0
189198
[2.0.0]: https://github.com/brainelectronics/micropython-modbus/tree/2.0.0

umodbus/serial.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def __init__(self,
109109
else:
110110
self._ctrlPin = None
111111

112+
self._t1char = (1000000 * (data_bits + stop_bits + 2)) // baudrate
112113
if baudrate <= 19200:
113114
# 4010us (approx. 4ms) @ 9600 baud
114115
self._t35chars = (3500000 * (data_bits + stop_bits + 2)) // baudrate
@@ -172,7 +173,9 @@ def _uart_read(self) -> bytearray:
172173
# variable length function codes may require multiple reads
173174
if self._exit_read(response):
174175
break
175-
time.sleep(0.05)
176+
177+
# wait for the maximum time between two frames
178+
time.sleep(self._t35chars)
176179

177180
return response
178181

@@ -245,13 +248,15 @@ def _send(self, modbus_pdu: bytes, slave_addr: int) -> None:
245248

246249
if self._ctrlPin:
247250
self._ctrlPin(1)
251+
time.sleep_us(1000) # wait until the control pin really changed
252+
send_start_time = time.ticks_us()
248253

249254
self._uart.write(serial_pdu)
250255

251256
if self._ctrlPin:
252-
while not self._uart.wait_tx_done(2):
257+
total_frame_time_us = self._t1char * len(serial_pdu)
258+
while time.ticks_us() <= send_start_time + total_frame_time_us:
253259
machine.idle()
254-
time.sleep_us(self._t35chars)
255260
self._ctrlPin(0)
256261

257262
def _send_receive(self,

0 commit comments

Comments
 (0)