问题描述
我尝试使用 python 2.7 编写一个程序,该程序在设备(函数生成器)中发送一些命令。该函数发生器带有一个与 Windows 驱动程序连接的软件。在 USB 端口分析器的帮助下,我读取了通过 USB 端口发送软件的原始数据。之后用我的程序重放这些记录的数据,它运行良好。但是当我开始发送更多数据(3 或 4 条消息)时,会出现如下所示的错误。
''''''''''''''''''''''''''''''''''''''''''ERROR'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Traceback (most recent call last):
File "b.py",line 51,in <module>
ep.write('aa550100ff00ffef3600ff00000074696d6572206c6f636b00'.decode('hex')')
File "C:\Python27\lib\site-packages\usb\core.py",line 406,in write
return self.device.write(self,data,timeout)
File "C:\Python27\lib\site-packages\usb\core.py",line 982,in write
self.__get_timeout(timeout)
File "C:\Python27\lib\site-packages\usb\backend\libusb0.py",line 549,in bulk_write
data,timeout)
File "C:\Python27\lib\site-packages\usb\backend\libusb0.py",line 659,in __write
timeout
File "C:\Python27\lib\site-packages\usb\backend\libusb0.py",line 447,in _check
raise USBError(errmsg,ret)
usb.core.USBError: [Errno None] libusb0-dll:err [_usb_reap_async] timeout error
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
import time
# find our device
dev = usb.core.find(idvendor=0x5345,idProduct=0x1234)
# was it found?
if dev is None:
raise ValueError('Device not found')
# set the active configuration. With no arguments,the first
# configuration will be the active one
dev.set_configuration()
# get an endpoint instance
cfg = dev.get_active_configuration()
intf = cfg[(0,0)]
ep = usb.util.find_descriptor(
intf,# match the first OUT endpoint
custom_match = \
lambda e: \
usb.util.endpoint_direction(e.bEndpointAddress) == \
usb.util.ENDPOINT_OUT)
assert ep is not None
# write the data
ep.write('aa550100ff00ffef3600ff00000074696d6572206c6f636b00'.decode('hex'))
ep.write('aa550100ff00ffef3600ff00000074696d6572206c6f636b00'.decode('hex'))
ep.write('aa550100ff00ffef3600ff00000074696d6572206c6f636b00'.decode('hex'))
ep.write('aa550100ff00ffef3600ff00000074696d6572206c6f636b00'.decode('hex'))
ep.write('aa550100ff00ffef360030'.decode('hex'))
ep.write('aa550100ff00ffef360030'.decode('hex'))
ep.write('aa550100ff00ffef360030'.decode('hex'))
ep.write('aa550100ff00ffef360030'.decode('hex'))
现在有人知道是什么导致了这个问题吗? 提前致谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)