Python Wiiuse connect()输出袜子:无效的参数

时间:2019-02-25 18:15:56

标签: python wiimote

我正在尝试使用python代码连接到wii远程

    import wiiuse

import sys
import time
import os

nmotes = 2

def handle_event(wmp):
    wm = wmp[0]
    print(" -- Event [wiimote id %i] --" % wm.unid)

    if wm.btns:
        for name, b in wiiuse.button.items():
            if wiiuse.is_pressed(wm, b):
                print(name, 'pressed')

def handle_ctrl_status(wmp, attachment, speaker, ir, led, battery_level):
    wm = wmp[0]
    print('--- Controller Status [wiimote id %i] ---' % wm.unid)
    print('attachment', attachment)
    print('speaker', speaker)
    print('ir', ir)
    print('leds', led[0], led[1], led[2], led[3])
    print('battery', battery_level)

def handle_disconnect(wmp):
    print()

if os.name != 'nt':
    print("Press 1 & 2")

wiimotes = wiiuse.init(nmotes)

found = wiiuse.find(wiimotes, nmotes, 5)
if not found:
    print("None found")
    sys.exit()

connected = wiiuse.connect(wiimotes, nmotes)
if connected:
    print("Connected")
else:
    print("Failed")

for i in range(nmotes):
    wiiuse.set_leds(wiimotes[i], wiiuse.LED[i])

try:
    rum = 1
    while True:
        r = wiiuse.poll(wiimotes, nmotes)
        if r != 0:
            handle_event(wiimotes[0])
except KeyboardInterrupt:
    for i in range(nmotes):
        wiiuse.set_leds(wiimotes[i], 0)
        wiiuse.rumble(wiimotes[i], 0)
        wiiuse.disconnect(wiimotes[i])

但是第40行存在问题。它不断抛出

connect() output sock: Invalid argument

我首先想到的是蓝牙存在问题,但是程序wmgui运行得很好。您还可以看到它确实找到了遥控器,但是随后的一段代码正在抛出它。我的想法是,它不喜欢将其分配给变量“ wiimotes”,但是这很奇怪,因为wiimotes是由它们自己的函数“ wiiuse.init(nmotes)”定义的。我最后的假设是它与套接字有关,而我没有经验。

规格:Raspberry Pi Model 3 B +,Python 3.4.2,Wiiuse 0.12,IDE Vscode

0 个答案:

没有答案