大家好,一个月前我的侄女不小心弄坏了我的任天堂开关控制器(https://www.powera.com/products/pokemon-wired-controller-for-nintendo-switch-pikachu-silhouette/),我决定尝试使用覆盆子 3b+ 与我的 Nintendo Switch 进行通信……我之前从未使用过 Python 编程,更不用说使用覆盆子了,所以我是一个完整的新手。所以3周后,我得到了这个代码:
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
有谁如何解决这个错误?