我想通过Python中的Libusb库连接到鼠标或ADNS2620鼠标传感器评估板。我在下面的代码中进行了必要的连接(以前在stackoverflow中发布过)。但对我来说 (“提高USBError(errmsg,ret)” usb.core.USBError:[Errno None]libusb0-dll:错误[控制消息]发送控制消息失败,win错误:连接到系统的设备不工作。“)出现错误并中断鼠标和计算机之间的连接。你知道吗
你如何提出克服这个错误的方法?你知道吗
其次,如何使用鼠标传感器访问从光学读取器接收到的像素?你知道吗
(我也在使用python2.7和Windows-10)
import usb.core
import usb.util
import matplotlib.pyplot as plt
import numpy as np
# VENDOR_ID = 0x16C0
# PRODUCT_ID = 0x03E8
VENDOR_ID = 0x1038 #UNBOX MOUSE
PRODUCT_ID = 0x1366
# find the USB device
device = usb.core.find(idVendor=VENDOR_ID,
idProduct=PRODUCT_ID)
print device
# use the first/default configuration
device.set_configuration(1)
# In order to read the pixel bytes, reset PIX_GRAB by sending a write command
response = device.ctrl_transfer(bmRequestType = 0x40, #Write
bRequest = 0x01,
wValue = 0x0000,
wIndex = 0x0D, #PIX_GRAB register value
data_or_wLength = None
)
# Read all the pixels (360 in this chip)
pixList = []
while len(pixList) < 361:
temp = 0
response = device.ctrl_transfer(bmRequestType = 0xC0, #Read
bRequest = 0x01,
wValue = 0x0000,
wIndex = 0x0D, #PIX_GRAB register value
data_or_wLength = 1
)
if response[0] >= 0x80:
temp = response[0] & 0x7F
pixList.append(temp)
pixelArray = np.asarray(pixList)
pixelArray = pixelArray.reshape((19,19))
plt.imshow(pixelArray)
plt.show()
目前没有回答
相关问题 更多 >
编程相关推荐