对于我的程序,我需要检测一个Arduino板一旦被断开,然后重新连接,在我的程序运行。我已经完美地检测到断开,但当重新连接板,程序无法处理它。你知道吗
我试着为此编写代码(这是一个UI,我需要就电路板的连接状态进行通信):
def update(self):
try:
ser.write('P')
time.sleep(0.1)
if ser.read() == "V":
self.photo=PhotoImage(file ='buttongreen.gif')
else:
self.photo=PhotoImage(file ='buttonred.gif')
ser.close()
except:
try:
ser.open()
if ser.read() == "V":
self.photo=PhotoImage(file ='buttongreen.gif')
else:
self.photo=PhotoImage(file ='buttonred.gif')
except:
self.photo=PhotoImage(file ='buttonred.gif')
pic = Canvas(self,width =64, height = 64, bg ='blue')
pic.grid(row=1, columnspan=3,column=1,padx = 10, pady =10)
pic.create_image(34,34, image=self.photo)
有没有可能解决这个问题,怎么解决?谢谢!你知道吗
编辑:我正在使用Tkinter、Python2.7和Arduino Uno和Leornardo
我要做的是:
Works for me
这符合你的期望吗?你知道吗
顺便说一下,千万不要写
try: except:
。总是说你在抓什么。你知道吗相关问题 更多 >
编程相关推荐