我对Python和Python很生疏。我的大部分背景来自微处理器工作,如arduinos和basic stamp。在
所以我写了一些东西,能从操纵杆控制一个IP摄像机。计划是使用像Pi这样的东西来运行代码。该程序将读取一个usb操纵杆,并将其转换为摄像头API的URL。我已经走到了这一步,但有一个问题。在
在linux操作系统上运行的代码proberly 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
调用来关闭缓冲。在相关问题 更多 >
编程相关推荐