USB 闪电探测器在通电后仅发送几秒钟数据

问题描述 投票:0回答:1

我正在使用通过 USB 连接到我的 Ubuntu 机器的 LD-350 闪电探测器。我遇到过一个问题,即从设备读取的数据只有在物理拔下设备的电源线然后重新插入后才会立即变得详细且有用。USB 线与 LD-350 的电源线是分开的并且拔下再连接 USB 电缆没有任何作用。尝试使用 RESET<> 在我的代码中重置设备没有成功。

问题: 当设备连续连接时,它主要发送简单且重复的数据数组,如[49, 96]。然而,在我重新连接设备后,它开始发送复杂而详细的数据数组,这正是我所需要的。这种详细的输出仅持续一段时间,然后就会恢复为简单的输出。

典型输出与所需输出:

Data read from device:
array('B', [49, 96])
array('B', [49, 96])
array('B', [49, 96])

所需输出(重新启动设备后立即):

Data read from device:
array('B', [49, 96, 58, 82, 69, 83, 69, 84, 13, 10, 58, 86, 69, 82, 32, 76, 68, 51, 53, 48, 45, 86, 49, 46, 49, 51, 13, 10])
array('B', [49, 96, 58, 76, 84, 83, 51, 32, 48, 13, 10])
array('B', [49, 96, 58, 87, 73, 77, 76, 73, 44, 50, 53, 52, 44, 52, 49, 55, 44, 49, 50, 52, 46, 53, 42, 53, 66, 13, 10])

设置:

OS: Ubuntu 20.04
Language: Python 3.8
Libraries: PyUSB

我尝试过的:

通过USB发送“RESET”命令和“RAW 1”命令来模拟重连初始化。 使用 dmesg 进行监控,但它仅显示正在识别的设备,而没有详细说明数据处理。 使用 Wireshark 捕获 USB 数据包,但我不确定在数据中寻找什么可以解释或解决问题。 我的代码:

import usb.core
import usb.util
import sys
import time

# Setup and find the device
dev = usb.core.find(idVendor=0x0403, idProduct=0xf241)
if dev is None:
    print('Device not found')
    sys.exit(1)

if dev.is_kernel_driver_active(0):
    dev.detach_kernel_driver(0)
dev.set_configuration()

# Send RESET and RAW commands
dev.write(1, 'RESET\r'.encode())
dev.write(1, 'RAW 1\r'.encode())

# Read data from the device
endpoint = dev[0][(0,0)][0]
while True:
    try:
        data = dev.read(endpoint.bEndpointAddress, endpoint.wMaxPacketSize)
        print('Data read from device:', data)
    except usb.core.USBError as e:
        print('Error:', e)

如何确保设备持续提供详细数据,而无需重新物理供电?是否有特定的设置或初始化序列通常需要在连接时发送到此类 USB 设备,而我可能会丢失?

python python-3.x libusb pyusb
1个回答
0
投票

我最终找到了解决方案,即每秒发送一次保持活动状态,以十六进制形式,即“4B 41 0A”,翻译为 KA。也就是说,保持活力。

© www.soinside.com 2019 - 2024. All rights reserved.