feat: 修订了调试功能
这个提交包含在:
@ -85,30 +85,27 @@ class Oscilloscope:
|
||||
self._attached_drivers.clear()
|
||||
|
||||
def send_command_raw(self, cmd: bytes, timeout: int = DEFAULT_TIMEOUT_MS) -> Optional[bytes]:
|
||||
"""
|
||||
发送SCPI命令并返回响应数据。
|
||||
:param cmd: SCPI命令字符串(会自动添加换行符)
|
||||
:param timeout: 超时时间(毫秒)
|
||||
:return: 响应字节数据,若失败则返回None
|
||||
"""
|
||||
if self.device is None or self.ep_out is None or self.ep_in is None:
|
||||
raise RuntimeError("设备未连接,请先调用connect()")
|
||||
|
||||
# 发送命令
|
||||
max_packet = self.ep_in.wMaxPacketSize
|
||||
|
||||
# 冲洗输入缓冲区,避免读到上一次命令的残留数据
|
||||
try:
|
||||
while True:
|
||||
self.device.read(self.ep_in, max_packet, timeout=50)
|
||||
except usb.core.USBError:
|
||||
pass
|
||||
|
||||
try:
|
||||
# self.device.write(self.ep_out.bEndpointAddress, cmd_bytes, timeout=timeout)
|
||||
self.device.write(self.ep_out, cmd, timeout=timeout)
|
||||
# self.ep_out.write(cmd_bytes, timeout)
|
||||
except usb.core.USBError as e:
|
||||
print(f"发送命令失败: {e}")
|
||||
return None
|
||||
|
||||
# 读取响应(直到超时或收到短包)
|
||||
response = b''
|
||||
max_packet = self.ep_in.wMaxPacketSize # type: ignore
|
||||
while True:
|
||||
try:
|
||||
# data = self.device.read(self.ep_in.bEndpointAddress, max_packet, timeout=timeout)
|
||||
data = self.device.read(self.ep_in, max_packet, timeout=timeout)
|
||||
if not data:
|
||||
break
|
||||
@ -116,7 +113,7 @@ class Oscilloscope:
|
||||
if len(data) < max_packet:
|
||||
break
|
||||
except usb.core.USBError as e:
|
||||
if e.errno == 110: # 超时,表示没有更多数据
|
||||
if e.errno == 110:
|
||||
break
|
||||
else:
|
||||
print(f"读取响应失败: {e}")
|
||||
|
||||
在新工单中引用
屏蔽一个用户