从Logitech G29读取USB数据

时间:2018-07-02 11:45:38

标签: python-2.7 libusb-1.0 logitech

嗨,我想知道是否有人对如何从Logitech G29读取USB数据有想法?

我目前正在使用python和usb1.py尝试读取数据,但到目前为止,我收到以下错误:

Traceback (most recent call last):

   file "force_feedback.py", line 548, in <module>
        logitech_device.read_data()
      /force_feedback.py", line 155, in read_data
        result = self.handle.interruptRead(self.ENDPOINT_READ, 64, timeout=155)
      File "usb1.py", line 1401, in interruptRead
        transferred = self._interruptTransfer(endpoint, data, length, timeout)
      File "usb1.py", line 1369, in _interruptTransfer
        mayRaiseUSBError(result)
      File "usb1.py", line 106, in mayRaiseUSBError
        raiseUSBError(value)
      File "usb1.py", line 102, in raiseUSBError
        raise STATUS_TO_EXCEPTION_DICT.get(value, USBError)(value)
    usb1.USBErrorTimeout: LIBUSB_ERROR_TIMEOUT [-7]

出现错误时我正在使用的代码如下:

class MissingLogitech(Exception):
    """No Logitech steering wheel found on USB."""    

class G29(object):
    VENDID = 0x046D
    PRODID = 0xC24F
    ENDPOINT_WRITE = 0x01
    ENDPOINT_READ = 0x81
    INTERFACE = 0

    def open(self):
        self.context = usb1.USBContext()
        self.dev = self.context.getByVendorIDAndProductID(self.VENDID, self.PRODID)
        if not (self.dev):
            raise MissingLogitech()
        else:
            print('Logitech G29 device is connected!')
        self.handle = self.dev.open()
        self.handle.resetDevice()
        self.handle.claimInterface(self.INTERFACE)
        self.handle.setConfiguration(1)


    def close(self):
        self.handle.releaseInterface(self.INTERFACE)
        self.handle.close()

    def read_data(self):
        result = self.handle.interruptRead(self.ENDPOINT_READ, 64, timeout=155)
        result = map(ord, result)
        return list(result)



G29()
G29.open()
buf = G29.read_data()

0 个答案:

没有答案