尝试使用USB与Raspberry 3b +通信Nintendo交换机

问题描述 投票:0回答:1

一个月前大家好,我的侄女无意间破坏了我的Nintendo Switch控制器(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

有人可以解决此错误吗?

python python-3.x usb uistatusbar nintendo
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.