-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_minimal.py
More file actions
58 lines (53 loc) · 1.39 KB
/
Copy pathrun_minimal.py
File metadata and controls
58 lines (53 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python3
"""
PAROL6 Headless Commander 最小化启动器
直接初始化串口并运行原始程序
"""
import os
import sys
import serial
import platform
# 设置环境
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
os.environ['PYTHONPATH'] = os.pathsep.join([
os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
os.environ.get('PYTHONPATH', '')
])
# 初始化串口
print("🔧 初始化串口...")
try:
ser = serial.Serial(
port='/dev/ttyACM0',
baudrate=3000000,
timeout=0
)
com_port_str = '/dev/ttyACM0'
print(f"✅ 串口连接成功: {com_port_str}")
except Exception as e:
print(f"❌ 串口初始化失败: {e}")
sys.exit(1)
# 设置全局变量
import builtins
builtins.ser = ser
builtins.com_port_str = com_port_str
builtins.my_os = platform.system()
# 运行原始程序
print("🚀 启动PAROL6 Headless Commander...")
print("-" * 50)
try:
exec(open('headless_commander.py').read(), {
'__name__': '__main__',
'ser': ser,
'com_port_str': com_port_str,
'my_os': platform.system()
})
except KeyboardInterrupt:
print("\n⏹️ 程序被用户中断")
except Exception as e:
print(f"\n❌ 运行错误: {e}")
import traceback
traceback.print_exc()
finally:
if ser and ser.is_open:
ser.close()
print("🔌 串口已关闭")