Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement support for broadcast #100

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements-deploy.txt
Original file line number Diff line number Diff line change
@@ -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.*
Copy link
Author

@T0RAT0RA T0RAT0RA Jan 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got an error in the CI that I couldn't find a solution for. Upgrading to 6 solved the issue (locally).
I'm not familiar with your CI/CD pipeline, so not sure it won't break anything.

The error in CI:

Run rm dist/*.orig
  rm dist/*.orig
  twine check dist/*.tar.gz
  shell: /usr/bin/bash -e {0}
  env:
    pythonLocation: /opt/hostedtoolcache/Python/3.9.21/x64
    LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.9.21/x64/lib
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.9.21/x64/bin/twine", line 5, in <module>
    from twine.__main__ import main
  File "/opt/hostedtoolcache/Python/3.9.21/x64/lib/python3.9/site-packages/twine/__init__.py", line 43, in <module>
    __license__ = metadata["license"]
  File "/opt/hostedtoolcache/Python/3.9.21/x64/lib/python3.9/site-packages/importlib_metadata/_adapters.py", line 54, in __getitem__
    raise KeyError(item)
KeyError: 'license'
Error: Process completed with exit code 1.

changelog2version>=0.5.0,<1
3 changes: 3 additions & 0 deletions umodbus/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 11 additions & 2 deletions umodbus/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __init__(self,
parity=parity,
pins=pins,
ctrl_pin=ctrl_pin),
[addr]
[Const.BROADCAST_ADDR, addr]
)


Expand Down Expand Up @@ -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.

Expand All @@ -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],
Expand Down Expand Up @@ -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,
Expand Down