Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python3读取USB操纵杆_Python_Python 3.x_Usb_Joystick - Fatal编程技术网

Python3读取USB操纵杆

Python3读取USB操纵杆,python,python-3.x,usb,joystick,Python,Python 3.x,Usb,Joystick,我对python和python3非常熟悉。我的大部分背景来自微处理器工作,如arduinos和basic stamp 因此,我写了一些东西,能够控制一个IP摄像头从一个操纵杆。计划是使用类似Pi的东西来运行代码。该程序将读取usb操纵杆,并将其转换为摄像头API的URL。我已经走了这么远,但有一个问题 带有的代码可以在linux操作系统上运行,可能是ubuntu或raspbian 我已经走了这么远,似乎工作得很好,除了一个障碍,我遇到了一位代码,我用阅读操纵杆 这只是其余代码的一个片段 impo

我对python和python3非常熟悉。我的大部分背景来自微处理器工作,如arduinos和basic stamp

因此,我写了一些东西,能够控制一个IP摄像头从一个操纵杆。计划是使用类似Pi的东西来运行代码。该程序将读取usb操纵杆,并将其转换为摄像头API的URL。我已经走了这么远,但有一个问题

带有的代码可以在linux操作系统上运行,可能是ubuntu或raspbian

我已经走了这么远,似乎工作得很好,除了一个障碍,我遇到了一位代码,我用阅读操纵杆

这只是其余代码的一个片段

import sys

pipe = open('/dev/input/js0', 'rb') #open joystick 
action = []
while True:
    StickValue = readStik(pipe)
    print ("StickValue")

    def readStick(pipe):
        action = []
        while stop == 1:
            for character in pipe.read(1):
                action += [int(character)]
                if len(action) == 8:
                    StickValue = action
                    action = []
                    stop = 2
                    ##when joystick is stationary code hangs here.
                    return  StickValue


#do some more stuff here while waiting for new joystick inputs apposed to hanging
我可以理解为什么它在停止while循环之前会一直挂起,直到所有的8字节都被读出,但我正在努力找出如何绕过它,或者是否有更好的方法来读取操纵杆。我现在一直在看pygame,但这意味着需要对其余的代码进行重大的重写


谢谢

尝试通过将
buffering=0
添加到
open
调用来关闭缓冲