For my program, I need to detect an Arduino board once it has been disconnected then reconnected, during the run of my program. I have perfectly detected the disconnection, but when reconnect the board, the program doesn't deal with it.
I tried to make this code for that (this is an UI, and I need to communicate about the connection state of the board) :
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)
Is it possible to solve this problem and how do that? Thanks!
Edit : I'm working with Tkinter, Python 2.7 and an Arduino Uno and Leornardo