【发布时间】:2017-09-27 22:42:06
【问题描述】:
我正在尝试与 USB 设备建立通信。我确实在 Python 中安装了 libusb1 和 libusb,并为我正在与之通信的设备安装了驱动程序。该设备在设备管理器中显示为 libusb-win32-devices。我已尝试遵循本教程https://github.com/walac/pyusb/blob/master/docs/tutorial.rst 我不确定我做错了什么。
- Windows 10
- Python:2.7.15
- pyusb:版本 '1.0.2'
简单代码示例:
import usb
dev = usb.core.find(idVendor=0x0683, idProduct=0x4108)
if dev is None:
print 'Unable to find the usb device'
dev.set_configuration()
我收到此错误:
---------------------------------------------------------------------------
USBError Traceback (most recent call last)
Y:\All Projects\Lab Equipment\DataQ\python\DI-4108\DI_4108_SANDBOX.py in <module>()
9
10
---> 11 dev.set_configuration()
12
13 # get an endpoint instance
C:\Anaconda2\lib\site-packages\usb\core.pyc in set_configuration(self, configuration)
867 without arguments is enough to get the device ready.
868 """
--> 869 self._ctx.managed_set_configuration(self, configuration)
870
871 def get_active_configuration(self):
C:\Anaconda2\lib\site-packages\usb\core.pyc in wrapper(self, *args, **kwargs)
100 try:
101 self.lock.acquire()
--> 102 return f(self, *args, **kwargs)
103 finally:
104 self.lock.release()
C:\Anaconda2\lib\site-packages\usb\core.pyc in managed_set_configuration(self, device, config)
146
147 self.managed_open()
--> 148 self.backend.set_configuration(self.handle, cfg.bConfigurationValue)
149
150 # cache the index instead of the object to avoid cyclic references
C:\Anaconda2\lib\site-packages\usb\backend\libusb1.pyc in set_configuration(self, dev_handle, config_value)
792 @methodtrace(_logger)
793 def set_configuration(self, dev_handle, config_value):
--> 794 _check(self.lib.libusb_set_configuration(dev_handle.handle, config_value))
795
796 @methodtrace(_logger)
C:\Anaconda2\lib\site-packages\usb\backend\libusb1.pyc in _check(ret)
593 raise NotImplementedError(_strerror(ret))
594 else:
--> 595 raise USBError(_strerror(ret), ret, _libusb_errno[ret])
596
597 return ret
USBError: [Errno 2] Entity not found
我确实获得了有关我的设备的信息:
> DEVICE ID 0683:4108 on Bus 002 Address 005 ================= bLength
> : 0x12 (18 bytes) bDescriptorType : 0x1 Device bcdUSB
> : 0x200 USB 2.0 bDeviceClass : 0xff Vendor-specific
> bDeviceSubClass : 0x0 bDeviceProtocol : 0x0
> bMaxPacketSize0 : 0x40 (64 bytes) idVendor :
> 0x0683 idProduct : 0x4108 bcdDevice :
> 0x100 Device 1.0 iManufacturer : 0x1 Error Accessing
> String iProduct : 0x2 Error Accessing String
> iSerialNumber : 0x3 Error Accessing String
> bNumConfigurations : 0x1 CONFIGURATION 1: 500 mA
> ================================== bLength : 0x9 (9 bytes) bDescriptorType : 0x2 Configuration wTotalLength
> : 0x20 (32 bytes) bNumInterfaces : 0x1
> bConfigurationValue : 0x1 iConfiguration : 0x5 Error
> Accessing String bmAttributes : 0xc0 Self Powered
> bMaxPower : 0xfa (500 mA)
> INTERFACE 0: Vendor Specific ===========================
> bLength : 0x9 (9 bytes)
> bDescriptorType : 0x4 Interface
> bInterfaceNumber : 0x0
> bAlternateSetting : 0x0
> bNumEndpoints : 0x2
> bInterfaceClass : 0xff Vendor Specific
> bInterfaceSubClass : 0x0
> bInterfaceProtocol : 0x0
> iInterface : 0x4 Error Accessing String
> ENDPOINT 0x81: Bulk IN ===============================
> bLength : 0x7 (7 bytes)
> bDescriptorType : 0x5 Endpoint
> bEndpointAddress : 0x81 IN
> bmAttributes : 0x2 Bulk
> wMaxPacketSize : 0x40 (64 bytes)
> bInterval : 0x0
> ENDPOINT 0x1: Bulk OUT ===============================
> bLength : 0x7 (7 bytes)
> bDescriptorType : 0x5 Endpoint
> bEndpointAddress : 0x1 OUT
> bmAttributes : 0x2 Bulk
> wMaxPacketSize : 0x40 (64 bytes)
> bInterval : 0x0
那么,最后一个问题是:如何在 Windows 中获得权限?在 Linux 中,您可以通过 udev 来完成。如何在 Windows 中解决此问题?
【问题讨论】:
-
如果我尝试在其中写入(在 [82] 中:dev.write(1,'test'))。我得到 USBError: [Errno 13] Access denied (insufficient permissions)
-
我发现了一个问题。供应商提供的软件甚至看不到我试图与之交谈的设备。因此,下一步将是弄清楚为什么会发生这种情况。如果我发现任何东西,我会继续发布。顺便说一句,该设备是 DATAQ Instruments 的 DI-4108。我试图添加一个标签,但我没有足够的声誉。