如何使用 pyusb 控制 xbox 360 游戏手柄上的 LED

How to control the LED on an xbox 360 gamepad using pyusb

我希望使用 pyusb 与有线 xbox 360 游戏手柄进行交互。到目前为止,我可以很好地阅读,但我也想写,这样我就可以让 LED 停止闪烁。

看起来 here,我应该可以做到,但无论我尝试发送什么消息,我都无法控制 LED。以下是我到目前为止的代码,有什么建议吗?

import usb
dev = usb.core.find(idVendor=1118, idProduct=654)
dev.set_configuration()
readEP = dev[0][(0,0)][0] #endpoint to read from
writeEP = dev[0][(0,0)][1] #endpoint to write to

print readEP #should be: <ENDPOINT 0x81: Interrupt IN>
print writeEP #should be: <ENDPOINT 0x1: Interrupt OUT>

##read the startup messages
for i in range(4): #usually only 4 messages
  data = dev.read(readEP.bEndpointAddress,readEP.wMaxPacketSize,100)
  print len(data) #should be 3

##get initial button/axes state
data = dev.read(readEP.bEndpointAddress,readEP.wMaxPacketSize,100)
print len(data) #should be 20

##Try to set the LED to illuminate just one element (message 0x06).
##Each of the following commented-out attempts fails to leave only the first
##element illuminated and subsequent attempts at reading or writing yields
##"usb.core.USBError: [Errno 5] Input/Output Error"
dev.write(writeEP,'010306',100) 
# dev.write(writeEP,'0\x010306',100) 
# dev.write(writeEP,'66310',100) #decimal value of 0x010306

##attempt to read again
while True:
  data = dev.read(readEP.bEndpointAddress,readEP.wMaxPacketSize,100)

解决了;只需要尝试正在编写的字符串的更多变体。这是最终起作用的方法:

dev.write(writeEP,"\x01\x03\x06",0)