diff --git a/requirements-deploy.txt b/requirements-deploy.txt index 96b0350..2d1bf95 100644 --- a/requirements-deploy.txt +++ b/requirements-deploy.txt @@ -1,5 +1,5 @@ # List external packages here # Avoid fixed versions # # to upload package to PyPi or other package hosts -twine>=4.0.1,<5 +twine==6.* changelog2version>=0.5.0,<1 diff --git a/umodbus/const.py b/umodbus/const.py index eb940be..7ba71de 100644 --- a/umodbus/const.py +++ b/umodbus/const.py @@ -104,6 +104,9 @@ #: Modbus Application Protocol High Data Response length MBAP_HDR_LENGTH = const(0x07) +#: Broadcast address +BROADCAST_ADDR = const(0x00) + #: CRC16 lookup table CRC16_TABLE = ( 0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241, 0xC601, diff --git a/umodbus/serial.py b/umodbus/serial.py index 11b8bee..67222c0 100644 --- a/umodbus/serial.py +++ b/umodbus/serial.py @@ -64,7 +64,7 @@ def __init__(self, parity=parity, pins=pins, ctrl_pin=ctrl_pin), - [addr] + [Const.BROADCAST_ADDR, addr] ) @@ -292,7 +292,7 @@ def _send(self, modbus_pdu: bytes, slave_addr: int) -> None: def _send_receive(self, modbus_pdu: bytes, slave_addr: int, - count: bool) -> bytes: + count: bool) -> Union[bytes, None]: """ Send a modbus message and receive the reponse. @@ -311,6 +311,10 @@ def _send_receive(self, self._send(modbus_pdu=modbus_pdu, slave_addr=slave_addr) + if slave_addr == Const.BROADCAST_ADDR: + # Do not wait for response after a broadcast + return None + return self._validate_resp_hdr(response=self._uart_read(), slave_addr=slave_addr, function_code=modbus_pdu[0], @@ -386,6 +390,11 @@ def send_response(self, :param signed: Indicates if signed :type signed: bool """ + + if slave_addr == Const.BROADCAST_ADDR: + # Do not reply to broadcast messages + return + modbus_pdu = functions.response( function_code=function_code, request_register_addr=request_register_addr,