Skip to content

work via new wb-mqtt-serial rpc#25

Open
evgeny-boger wants to merge 6 commits into
masterfrom
feature/newrpc
Open

work via new wb-mqtt-serial rpc#25
evgeny-boger wants to merge 6 commits into
masterfrom
feature/newrpc

Conversation

@evgeny-boger

Copy link
Copy Markdown
Member

Что происходит; кому и зачем нужно:

Работаем через "новый" API wb-mqtt-serial Port/Load, чтобы он знал про протокол Modbus


Что поменялось для пользователей:

Стало быстрее. Собственно главная причина поддержки модбаса в Port/Load была в том, что можно хитро читать из порта, т.к. мы знаем сколько байтиков мы ожидаем в ответе.

Ну, ещё добавился режим RTU-over-TCP нахаляву (справедливости ради, он и без нового RPC бы добавлялся в две строчки), и в хелп немножко добавил полезного.


Как проверял/а:

Запускал с обычным wb-mqtt-serial, с патченным (см. свежий PR туда). Читал через него с mbgate и с обычных настоящих устройств.

@evgeny-boger evgeny-boger requested review from Copilot and sikmir July 25, 2025 08:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the Modbus client to use a new wb-mqtt-serial RPC API that has native Modbus protocol support, providing performance improvements and adding RTU-over-TCP mode support.

  • Replaces direct umodbus library calls with wb-mqtt-serial RPC API calls that understand Modbus protocol
  • Adds support for RTU-over-TCP mode (transparent serial-TCP bridge)
  • Simplifies message creation and parsing by leveraging the RPC service's Modbus knowledge

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
modbus_client_rpc/main.py Core refactoring to use new RPC API with native Modbus support, added RTU-over-TCP mode
tests/test_modbus_client.py Updated test cases to match new function signatures and RPC payload format
debian/changelog Version bump to 1.3.0 documenting the new RPC integration and RTU-over-TCP feature
Comments suppressed due to low confidence (1)

tests/test_modbus_client.py:95

  • The comment mentions reading 125 coils is allowed, but the test case uses 126. This inconsistency could indicate either an incorrect test case or an inaccurate comment.
    (0x01, True, 0, 126, [], "", 126, False),  # it's fun, but reading 125 *coils* is actually allowed

Comment thread modbus_client_rpc/main.py
Comment on lines +245 to +250
data = []
for byte in response_byte:
for bit in range(8):
data.append((byte >> bit) & 1)
if len(data) >= register_count:
break

Copilot AI Jul 25, 2025

Copy link

Choose a reason for hiding this comment

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

The bit extraction logic may read more bits than requested. When register_count is reached, the outer loop should also break to avoid processing additional bytes.

Suggested change
data = []
for byte in response_byte:
for bit in range(8):
data.append((byte >> bit) & 1)
if len(data) >= register_count:
break
data = []
done = False
for byte in response_byte:
for bit in range(8):
data.append((byte >> bit) & 1)
if len(data) >= register_count:
done = True
break
if done:
break

Copilot uses AI. Check for mistakes.
Comment thread modbus_client_rpc/main.py
print("SUCCESS: written 1 element")
else:
print("SUCCESS: Coils/Registers written:", data)
print("SUCCESS: Coils/Registers written:", "?")

Copilot AI Jul 25, 2025

Copy link

Choose a reason for hiding this comment

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

The hardcoded "?" placeholder should be replaced with the actual count of written coils/registers, which can be determined from the register_count parameter.

Suggested change
print("SUCCESS: Coils/Registers written:", "?")
print("SUCCESS: Coils/Registers written:", register_count)

Copilot uses AI. Check for mistakes.
@evgeny-boger

Copy link
Copy Markdown
Member Author

ну может и год повисеть, чего уж тут

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants