Repository navigation
Add TCP, MQTT and Modbus TCP communication links - #1
Merged
Merged
Conversation
A CommHub owns the serial, TCP (QtNetwork client/server) and MQTT (paho-mqtt) links. Every link reports through the same signals, so bindings, charts, tables and logs stay transport-agnostic, and commands go out over every connected link. TCP and MQTT configuration cards share one runtime card frame with the designer preview and exported projects, which now generate comm_hub.py, tcp_handler.py and mqtt_handler.py. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
A modbus_tcp parser mode frames responses by their MBAP header and produces the same dictionaries as the RTU parser, so existing Modbus bindings work unchanged over Ethernet devices. Modbus commands are now framed for each connected link: links parsing Modbus TCP receive MBAP requests with rolling transaction identifiers, every other link keeps receiving RTU frames with CRC. Widgets and the Modbus card need no new settings. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Checking against a real broker showed two gaps. While a TCP or MQTT link was connecting, or MQTT was retrying after a drop, both card buttons were disabled, so the attempt could not be cancelled; 断开 now cancels it and the card shows 重连中 during retries. MQTT refusals now name the reason (for example a bad user name or password), a plain connection loss no longer shows paho's "Unspecified error", paho 1 disconnect codes are no longer read as CONNACK codes, and a failed TLS connection points at the port and the server certificate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TCP client and server links, MQTT publish and subscribe, and Modbus TCP, all sharing the serial link's parsing, bindings and commands in the designer and in exported applications. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
补齐 README 里标为"开发中"的 TCP 和 MQTT 通信,并顺带支持标准 Modbus TCP(MBAP)。
改动
1. 通信中枢 + TCP / MQTT 链路(ed520c3)
CommHub(app/core/comm_runtime.py),统一持有串口、TCP、MQTT 三条链路。三条链路实现同一组信号,中枢汇总后转发给信号总线,所以数据绑定、实时曲线、表格、日志不需要改动就能接收任意链路的数据;命令会发往每一条已连接的链路。serialManager保留为commHub.serial的别名,旧调用方不受影响。tcp_runtime.py):基于 QtNetwork,全部在 GUI 线程,不新增读线程。支持客户端和服务端;服务端可同时接多个设备,每个连接独立切帧,命令写给所有已连接设备。mqtt_runtime.py):基于 paho-mqtt,兼容 1.x 和 2.x 回调签名。paho 线程的回调通过带代际号的队列信号转到 GUI 线程,旧客户端的迟到回调一律丢弃。每条消息按一帧解析;纯数值载荷额外以主题名为键,可直接按主题绑定。意外断线自动重连并恢复订阅;首次连接失败(地址错误、认证失败)不重试。支持用户名密码、QoS 0/1/2、TLS、通配符订阅。link_card.py基类,设计器预览和导出工程使用同一份源码。comm_hub.py、tcp_handler.py、mqtt_handler.py,main.py改为创建中枢;requirements.txt、导出的 requirements 和一键打包的依赖检查都加入paho-mqtt。TCP 127.0.0.1:8080)。2. Modbus TCP(9f343c9)
modbus_tcp:按 MBAP 头的长度字段切帧,校验协议标识和功能码对应长度;输出字典与 RTU 解析器完全一致(单元标识符放在slave),现有 Modbus 绑定无需修改即可接以太网设备。modbus_tcp的链路收到 MBAP 请求(事务标识符逐帧递增并在 65535 后回绕),其余链路照旧收到带 CRC 的 RTU 帧。控件和 Modbus 卡片不需要新增属性;请求只在发送前校验一次,非法请求不会发往任何链路。modbus_tcp。文档与 demo
docs/protocol.md新增"六、传输链路"一节和 Modbus TCP 帧格式参考。demo/用新生成器重新导出(test_demo要求提交的导出与生成结果逐字节一致)。测试
test_tcp_runtime.py(真实回环 socket)、test_mqtt_runtime.py(假 paho 客户端在后台线程触发回调)、test_comm_hub.py、test_link_cards.py(预览与导出一致性),并在test_protocol_runtime.py、test_command_runtime.py中补充 Modbus TCP 用例。dist_smoke.py新增真实 TCP 回环步骤,用来确认 QtNetwork 被打进编译产物。python -m unittest discover -s tests:全部通过python tests/smoke_gui.py:NATIVE_GUI_EXPORT_OK: 29 widget typespython deploy.py全量 Nuitka 打包成功,随后tests/smoke_dist.py对产物 zip 验证通过(compiled_runtime: true、tcp_loopback: true)审阅提示
docs/protocol.md第六节已写明。🤖 Generated with Claude Code