0

您好我正在尝试使用 usb1.py 在 Logitech G27 方向盘上实现力反馈。

我正在尝试使用这种力反馈协议:

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

当我将 interrupt_write 与 ENDPOINT1 一起使用时,我发送了 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()  

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

4

1 回答 1

0

我解决了它所在的问题

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

它应该是:Spring_off = bytearray([0xF5,0x00,0x00,0x00,0x00,0x00,0x00])相反。

于 2018-06-18T09:41:52.387 回答