gpt4 book ai didi

python - 尝试使用 USB 将 Nintendo Switch 与 Raspberry 3b+ 进行通信

转载 作者:太空宇宙 更新时间:2023-11-03 19:48:21 25 4
gpt4 key购买 nike

大家好,一个月前,我的侄女不小心弄坏了我的 Nintendo Switch Controller ( https://www.powera.com/products/pokemon-wired-controller-for-nintendo-switch-pikachu-silhouette/ ),我决定尝试使用树莓派 3b+ 与我的 Nintendo Switch 进行通信...我之前从未用 Python 编程过独自使用了覆盆子,所以我是一个完全的新手。三周后,我得到了这段代码:

import USB
import time

#Test to see if a Nintendo Switch is connected or no
switch = usb.core.find(idVendor=1406)
if switch is None:
print('Switch Not Detected')
exit(0)
else:
print('Switch Conected')
reconect = False

#Don't know why is this for but it helps to connect with the switch
if switch.is_kernel_driver_active(0):
reconect = True
switch.detach_kernel_driver(0)

switch.set_configuration()

cfg=switch.get_active_configuration()

interface_number = cfg[(0,0)].bInterfaceNumber
alternate_settting = usb.control.get_interface(switch, interface_number)
intf = usb.util.find_descriptor(cfg, bInterfaceNumber = interface_number,
bAlternateSetting = alternate_settting)

ep = usb.util.find_descriptor(intf,custom_match = \
lambda e: \
usb.util.endpoint_direction(e.bEndpoindAddress) == \
usb.util.ENDPOINT_OUT)

ep.write(b'\x00\x00\x00\x0f\x80\x80\x80\x80\x00') #Controller not pressed
time.sleep(0.1)
ep.write(b'\x04\x00\x0f\x80\x80\x80\x80\x00') #Controller "A" button pressed
time.sleep(0.1)
ep.write(b'\x00\x00\x00\x0f\x80\x80\x80\x80\x00') #Controller not pressed

usb.util.dispose_resources(dev)
if reconectar:
switch.attach_kernel_driver(0)

print('Communication Finished')

启动代码后,我收到此错误代码

>>> %FastDebug testedousb.py
Switch Conected
Traceback (most recent call last):
File "/home/pi/testedousb.py", line 41, in <module>
alternate_settting = usb.control.get_interface(switch, interface_number)
File "/usr/local/lib/python3.7/dist-packages/usb/control.py", line 244, in get_interface
data_or_wLength = 1)[0]
File "/usr/local/lib/python3.7/dist-packages/usb/core.py", line 1043, in ctrl_transfer
self.__get_timeout(timeout))
File "/usr/local/lib/python3.7/dist-packages/usb/backend/libusb1.py", line 883, in ctrl_transfer
timeout))
File "/usr/local/lib/python3.7/dist-packages/usb/backend/libusb1.py", line 595, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 32] Pipe error

谁能解决这个错误?

最佳答案

您可能想看看这个伟大的项目及其分支,而不是从头开始编写自己的代码:https://github.com/ebith/Switch-Fightstick

关于python - 尝试使用 USB 将 Nintendo Switch 与 Raspberry 3b+ 进行通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59997338/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com