【发布时间】:2016-10-23 20:01:14
【问题描述】:
我使用的 rPi 2B 已插入磁条读卡器(使用 PS/2 到 USB 转换器)。我使用 lsusb 确定了正确的供应商/产品 ID,然后使用以下代码使用 libusb 连接到阅读器。此代码检查is_kernel_driver_active,这似乎是此问题的主要错误来源。代码来自github上的keyboard_alike项目。
def initialize(self):
self._device = usb.core.find(idVendor=self.vendor_id, idProduct=self.product_id)
if self._device is None:
raise DeviceException('No device found, check vendor_id and product_id')
if self._device.is_kernel_driver_active(self.interface):
try:
self._device.detach_kernel_driver(self.interface)
except usb.core.USBError as e:
raise DeviceException('Could not detach kernel driver: %s' % str(e))
try:
self._device.set_configuration()
if self.should_reset:
self._device.reset()
except usb.core.USBError as e:
raise DeviceException('Could not set configuration: %s' % str(e))
self._endpoint = self._device[0][(0, 0)][0]
当以 root 身份执行时,我在调用 self._device.set_configuration() 时收到一个 Resource busy。
我已经运行了所有更新,但我不确定接下来要尝试什么。
【问题讨论】:
标签: python raspberry-pi pyusb libusb-1.0