chore: 使用默认TOML配置文件
This commit is contained in:
@@ -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 轮询周期和连续超时判定次数。
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user