“ win错误:连接到系统的设备不起作用。”错误

时间:2019-04-16 13:03:30

标签: python libusb pyusb

我想通过Python中的Libusb库连接到鼠标或ADNS2620鼠标传感器评估板。我在以下代码中进行了必要的连接(该代码先前已在stackoverflow中发布)。但是对我来说 (“提高USBError(errmsg,ret) usb.core.USBError:[Errno无] libusb0-dll:err [control_msg]发送控制消息失败,WIN错误:连接到系统的设备无法运行。 “)出现错误并中断鼠标与计算机之间的连接。

您如何提出克服此错误的方法?

第二,如何使用鼠标传感器访问从光学阅读器接收的像素?

(我也正在使用Python 2.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()

0 个答案:

没有答案