From 0b39ef842e5c3bc13dfaa5986b5280a6284e53b9 Mon Sep 17 00:00:00 2001 From: chuan Date: Wed, 13 May 2026 14:18:01 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E4=BD=BF=E7=94=A8=E9=BB=98=E8=AE=A4TO?= =?UTF-8?q?ML=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- config.example.toml => config.toml | 0 src/line_laser_modbus/cli.py | 10 ++++------ 3 files changed, 6 insertions(+), 8 deletions(-) rename config.example.toml => config.toml (100%) diff --git a/README.md b/README.md index 69c3833..d844687 100644 --- a/README.md +++ b/README.md @@ -31,10 +31,10 @@ python -m uv run line-laser-modbus --simulate demo ## TOML 配置 -外部配置入口参考 `config.example.toml`。真实串口运行时可使用: +运行前按实际串口修改 `config.toml`。默认会读取当前目录下的 `config.toml`: ```powershell -python -m uv run line-laser-modbus --config config.example.toml read-status +python -m uv run line-laser-modbus read-status ``` 配置文件包含 `[serial]` 和 `[polling]` 两段,其中 `[polling]` 用于配置 20ms 轮询周期和连续超时判定次数。 diff --git a/config.example.toml b/config.toml similarity index 100% rename from config.example.toml rename to config.toml diff --git a/src/line_laser_modbus/cli.py b/src/line_laser_modbus/cli.py index 4e45521..cd95589 100644 --- a/src/line_laser_modbus/cli.py +++ b/src/line_laser_modbus/cli.py @@ -3,9 +3,10 @@ from __future__ import annotations import argparse +from pathlib import Path from line_laser_modbus.client import LineLaserClient -from line_laser_modbus.config import AppConfig, SerialConfig +from line_laser_modbus.config import AppConfig from line_laser_modbus.models import ModeCommand, Pose6D from line_laser_modbus.runner import PollingRunner, pose_delta from line_laser_modbus.simulator import SimulatedModbusBackend @@ -13,8 +14,7 @@ from line_laser_modbus.simulator import SimulatedModbusBackend def main() -> None: parser = argparse.ArgumentParser(prog="line-laser-modbus") - parser.add_argument("--config", help="TOML config path") - parser.add_argument("--port", default="COM1", help="Serial port when no config is provided") + parser.add_argument("--config", default="config.toml", help="TOML config path") parser.add_argument("--simulate", action="store_true", help="Use in-memory simulator") subparsers = parser.add_subparsers(dest="command", required=True) @@ -26,9 +26,7 @@ def main() -> None: subparsers.add_parser("demo") args = parser.parse_args() - app_config = AppConfig.from_toml(args.config) if args.config else AppConfig( - serial=SerialConfig(port=args.port) - ) + app_config = AppConfig.from_toml(Path(args.config)) backend = SimulatedModbusBackend() if args.simulate else None with LineLaserClient(app_config.serial, backend=backend) as client: