使用libusb1和usb1.py

时间:2018-06-18 06:46:04

标签: python-2.7 libusb-1.0 logitech

您好我试图使用usb1.py在罗技G27方向盘上实施力反馈。

我试图使用此力反馈协议:

 https://opensource.logitech.com/opensource/images/c/ce/Logitech_Force_Feedback_Protocol_V1.5.pdf

当我在ENDPOINT1中使用interrupt_write时,我发送8个字节而不是协议使用的7个字节。

我试图通过在CMD位中发送0x05来关闭默认弹簧,但我不能让它工作。

我试图通过以下代码实现它:

g27_constants.py 
Spring_off = bytearray([0x05,0x00,0x00,0x00,0x00,0x00,0x00])

force_feedback.py
import sys
import time
import usb1 as usb
import libusb1
import os
import g27_constants as constG27


###################################################################################################################

# idn enl control panel
# USB\VID_046D&PID_C29B is the same as found on the internet.

# creating a logitech g27 class with all necessary files.


class MissingG27(Exception):
    """No G27 found on USB."""


class data_type_error(Exception):
    """Wrong data type!"""


class G27(object):
    VENDID = 0x046D
    PRODID = 0xC29B
    ENDPOINT = 1 
    INTERFACE = 0

    def __init__(self, temp):
        self.temp = temp

    def open(self):
        self.context = usb.USBContext()
        self.dev = self.context.getByVendorIDAndProductID(self.VENDID, self.PRODID)
        if not (self.dev):
            raise MissingG27()
        else:
            print('Logitech G27 device is connected!')
        self.handle = self.dev.open()
       # self.handle.resetDevice() unsure if this is needed!
        self.handle.claimInterface(self.INTERFACE)
        self.write_data(constG27.Spring_off) #turn off return spring.

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

    def write_data(self, buf):
        str_buf = ''.join(map(chr, buf))
        result = self.handle.interruptWrite(0x01, str_buf,timeout=255)
        if result != len(buf):
            print('Error did not send correct data sent ' + str(result) + ' bytes!' + ' \n buff size is: '
                  + str(len(buf)) + ' bytes.')
        else:
            print('Succes, You sent: ' + str(result) + ' bytes!')


    g27_device = G27(0)
    g27_device.open()  

任何人都知道我做错了什么?

1 个答案:

答案 0 :(得分:0)

我解决了它的问题

Spring_off = bytearray([0x05,0x00,0x00,0x00,0x00,0x00,0x00])

应该是:Spring_off = bytearray([0xF5,0x00,0x00,0x00,0x00,0x00,0x00])而不是。