28 lines
784 B
Python
28 lines
784 B
Python
"""真实串口读取状态示例"""
|
|
|
|
from pathlib import Path
|
|
|
|
from line_laser_modbus import AppConfig, LineLaserClient
|
|
|
|
|
|
def main() -> None:
|
|
"""从 config.toml 读取串口配置并读取设备状态"""
|
|
|
|
# 运行这个示例前先修改项目根目录的 config.toml
|
|
# port 需要改成现场电脑实际看到的串口名
|
|
# Windows 常见格式是 COM1 或 COM3
|
|
config = AppConfig.from_toml(Path("config.toml"))
|
|
|
|
# 真实串口路径不注入 backend
|
|
# LineLaserClient 会自动创建 pymodbus 串口客户端
|
|
with LineLaserClient(config.serial) as client:
|
|
status = client.read_status()
|
|
pose = client.read_current_pose()
|
|
|
|
print("设备状态", status.name)
|
|
print("当前位姿", pose)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|