my project is to build a scanner that send the sensor value on Serial port. I want to control the scanner using a GUI Tkinter, so I want to check if something is coming on the serial continuously. However, I used the .after() function that works when something is sent but when the scanner is "waiting" and nothing is sent, the GUI freezes and I can't to do anything until something is sent. Thanks,
Here's the code triggered by the main button:
def Acqard():
global flag
flag = 1
arduinoData.write(b'1')
log.insert(END, "Début du scan\n")
root.after(10, write_data)
And here are the functions that save the DATA in a txt file:
def write_data():
global file_stream
file_stream = open("data.txt", "a") # mode write ou append ?
write_lines()
def write_lines():
global after_id
data = arduinoData.read()
try:
data2 = data.decode("utf-8")
file_stream.write(data2)
print(data2)
if data2 == "F":
root.after_cancel(after_id)
print("Ca a marché")
stopacq()
after_id = root.after(10, write_data)
except:
return
And here's the function that stops the scanner:
def stopacq():
global flag, file_stream
flag = 0
root.after_cancel(after_id)# Annulation des rappels automatiques de write_lines
file_stream.close()
file_stream = None
arduinoData.write(b'3')
log.insert(END, "Scan interrompu\n")