You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

27 lines
855 B

# region 串口通信
# 初始化串口
import threading
import serial
def serial_init():
try:
ser = serial.Serial(
port="/dev/ttyS0", # 笔记本Windows端口,Linux/Mac替换为"/dev/ttyUSB0"
baudrate=115200,
timeout=0.1
)
print("串口初始化成功")
return ser
except Exception as e:
print(f"笔记本串口初始化失败: {e}")
return None
# 矩阵转换函数:将P_L1_O2通过R_T转换为P_L1_O1
class SerialSharedData:
"""线程安全的串口数据共享存储类"""
def __init__(self):
self.lock = threading.Lock() # 防止多线程数据竞争
self.buffer = b'' # 用于解析0xFF坐标帧的通用缓冲区
self.cmd_buffer = b'' # 用于解析0xAA指令帧(主指令/子指令/停止指令)的缓冲区