diff --git a/changelog.md b/changelog.md index 6377292..9b8c9e4 100644 --- a/changelog.md +++ b/changelog.md @@ -15,6 +15,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Released +## [2.4.0] - 2023-07-20 +### Added +- The following fixes were provided by @sandyscott +- UART signals can be inverted with the `invert` argument of the `Serial` and `ModbusRTU` class constructors + ## [2.3.7] - 2023-07-19 ### Fixed - Add a single character wait time after flush to avoid timing issues with RTU control pin, see #68 and #72 @@ -307,8 +312,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - PEP8 style issues on all files of [`lib/uModbus`](lib/uModbus) -[Unreleased]: https://github.com/brainelectronics/micropython-modbus/compare/2.3.7...develop +[Unreleased]: https://github.com/brainelectronics/micropython-modbus/compare/2.4.0...develop +[2.4.0]: https://github.com/brainelectronics/micropython-modbus/tree/2.4.0 [2.3.7]: https://github.com/brainelectronics/micropython-modbus/tree/2.3.7 [2.3.6]: https://github.com/brainelectronics/micropython-modbus/tree/2.3.6 [2.3.5]: https://github.com/brainelectronics/micropython-modbus/tree/2.3.5 diff --git a/fakes/machine.py b/fakes/machine.py index 46fc358..cfb6a36 100755 --- a/fakes/machine.py +++ b/fakes/machine.py @@ -27,6 +27,11 @@ class UART(object): See https://docs.micropython.org/en/latest/library/machine.UART.html """ + # ESP32: TX=32, RX=4 + # RP2: TX=1, RX=2 + INV_RX = 4 + INV_TX = 32 + def __init__(self, uart_id: int, baudrate: int = 9600, @@ -35,7 +40,8 @@ def __init__(self, stop: int = 1, tx: int = 1, rx: int = 2, - timeout: int = 0) -> None: + timeout: int = 0, + invert: int = 0) -> None: self._uart_id = uart_id if timeout == 0: timeout = 5.0 diff --git a/package.json b/package.json index a34361d..0ad00b7 100644 --- a/package.json +++ b/package.json @@ -38,5 +38,5 @@ ] ], "deps": [], - "version": "2.3.7" + "version": "2.4.0" } \ No newline at end of file diff --git a/umodbus/serial.py b/umodbus/serial.py index 11b8bee..25f918a 100644 --- a/umodbus/serial.py +++ b/umodbus/serial.py @@ -26,6 +26,10 @@ class ModbusRTU(Modbus): + # Include in class so they can be used when creating the object + INV_RX = UART.INV_RX + INV_TX = UART.INV_TX + """ Modbus RTU client class @@ -45,7 +49,10 @@ class ModbusRTU(Modbus): :type ctrl_pin: int :param uart_id: The ID of the used UART :type uart_id: int + :param invert: Invert TX and/or RX pins + :type invert: int """ + def __init__(self, addr: int, baudrate: int = 9600, @@ -54,7 +61,8 @@ def __init__(self, parity: Optional[int] = None, pins: List[Union[int, Pin], Union[int, Pin]] = None, ctrl_pin: int = None, - uart_id: int = 1): + uart_id: int = 1, + invert: int = 0): super().__init__( # set itf to Serial object, addr_list to [addr] Serial(uart_id=uart_id, @@ -63,12 +71,17 @@ def __init__(self, stop_bits=stop_bits, parity=parity, pins=pins, - ctrl_pin=ctrl_pin), + ctrl_pin=ctrl_pin, + invert=invert), [addr] ) class Serial(CommonModbusFunctions): + # Include in class so they can be used when creating the object + INV_RX = UART.INV_RX + INV_TX = UART.INV_TX + def __init__(self, uart_id: int = 1, baudrate: int = 9600, @@ -76,7 +89,8 @@ def __init__(self, stop_bits: int = 1, parity=None, pins: List[Union[int, Pin], Union[int, Pin]] = None, - ctrl_pin: int = None): + ctrl_pin: int = None, + invert: int = 0): """ Setup Serial/RTU Modbus @@ -94,6 +108,8 @@ def __init__(self, :type pins: List[Union[int, Pin], Union[int, Pin]] :param ctrl_pin: The control pin :type ctrl_pin: int + :param invert: Invert TX and/or RX pins + :type invert: int """ # UART flush function is introduced in Micropython v1.20.0 self._has_uart_flush = callable(getattr(UART, "flush", None)) @@ -105,7 +121,8 @@ def __init__(self, # timeout_chars=2, # WiPy only # pins=pins # WiPy only tx=pins[0], - rx=pins[1] + rx=pins[1], + invert=invert ) if ctrl_pin is not None: diff --git a/umodbus/version.py b/umodbus/version.py index e6b8ffa..e4e72d1 100644 --- a/umodbus/version.py +++ b/umodbus/version.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 # -*- coding: UTF-8 -*- -__version_info__ = ("2", "3", "7") +__version_info__ = ("2", "4", "0") __version__ = '.'.join(__version_info__)