6e80d5fa41f8a295be0368a6d5ecc886dea9541a
line-laser-modbus
线激光器上位机与运动控制器的 Modbus RTU 通信模块,覆盖模式命令、设备状态、6 轴位姿、目标示教位姿和 6 轴纠偏量的读写。
协议文档见 docs/proto.md。
功能
- 基于
pymodbus的 Modbus RTU 串口客户端 - 按协议实现 uint16、uint32 时间戳、float32、XYZABC 位姿和 CRC16 编解码
- 提供无硬件内存模拟器用于测试
- 提供模式状态机校验和 50ms 轮询运行器
- 使用 TOML 作为运行配置入口
安装与测试
python -m uv sync --default-index https://mirrors.ustc.edu.cn/pypi/simple
python -m uv run pytest
python -m uv run ruff check
模拟运行
python -m uv run line-laser-modbus --simulate read-status
python -m uv run line-laser-modbus --simulate write-mode 3
python -m uv run line-laser-modbus --simulate emergency-stop
python -m uv run line-laser-modbus --simulate poll-once --target 1 2 3 0 1 2
python -m uv run line-laser-modbus --simulate demo
示例代码
示例代码在 examples/ 目录下,优先阅读模拟示例了解库的调用方式:
python -m uv run python examples/simulated_basic.py
python -m uv run python examples/simulated_polling.py
连接真实串口前先修改 config.toml,再运行:
python -m uv run python examples/real_serial_read_status.py
TOML 配置
运行前按实际串口修改 config.toml。默认会读取当前目录下的 config.toml:
python -m uv run line-laser-modbus read-status
配置文件包含 [serial] 和 [polling] 两段,其中 [polling] 用于配置 50ms 轮询周期和连续超时判定次数。
类型标记
src/line_laser_modbus/py.typed 是 PEP 561 类型标记文件。它可以为空,文件存在本身就表示这个包发布后应被类型检查器按 typed package 处理。
Description
Languages
Python
100%