adicionados envios seriais para seleção de protocolos compatíveis com o firmware

parent 14b69fbb
......@@ -82,10 +82,12 @@ canvas4 = Canvas(canvas_big, bg='blue')
canvas4.place(relx=0.025, rely=0.725, relwidth=0.95, relheight=0.25)
log = Text(canvas4)
log.place(relx=0.025, rely=0.025, relwidth=0.5, relheight=0.8)
button_con = Button(canvas4, text="Detectar e conectar Arduino", command = lambda:detect_arduino())
button_con = Button(canvas4, text="Detectar e testar conexão de Arduino", command = lambda:detect_arduino())
button_con.place(relx=0.6, rely=0.075, relwidth=0.4, relheight=0.15)
button_send = Button(canvas4, text="Enviar", command = lambda:enviar_arduino())
button_send = Button(canvas4, text="Iniciar protocolos selecionados", command = lambda:send_protocol())
button_send.place(relx=0.6, rely=0.5, relwidth=0.4, relheight=0.15)
button_int = Button(canvas4, text="Interromper estimulação", command = lambda:interrupt_protocol())
button_int.place(relx=0.6, rely=0.7, relwidth=0.4, relheight=0.15)
def writeToLog(msg):
numlines = log.index('end - 1 line').split('.')[0]
......@@ -138,13 +140,13 @@ def select_protocol(canvas, protocol):
button_par_1.place(relx=0, rely=0.775, relwidth=1, relheight=0.075)
if (canvas==canvas1):
global prot1
prot1 = 'bu'
prot1 = "Basal Unipolar"
if (canvas==canvas2):
global prot2
prot2 = 'bu'
prot2 = "Basal Unipolar"
if (canvas==canvas3):
global prot3
prot3 = 'bu'
prot3 = "Basal Unipolar"
if (protocol=="TBS unipolar"):
prot_image = Image.open("protocolo_TBS.PNG")
......@@ -191,11 +193,11 @@ def select_protocol(canvas, protocol):
button_par_1 = Button(canvas, text="Selecionar parâmetros", command = lambda:select_par_TBS(canvas, T_entry.get(), IPI_entry.get(), n_ep_entry.get(), IEI_entry.get(), ITI_entry.get(), dur_entry.get()))
button_par_1.place(relx=0, rely=0.775, relwidth=1, relheight=0.05)
if (canvas==canvas1):
prot1 = 'tu'
prot1 = "TBS Unipolar"
if (canvas==canvas2):
prot2 = 'tu'
prot2 = "TBS Unipolar"
if (canvas==canvas3):
prot3 = 'tu'
prot3 = "TBS Unipolar"
if (protocol=="PBS"):
prot_image = Image.open("protocolo_PBS.PNG")
......@@ -242,11 +244,11 @@ def select_protocol(canvas, protocol):
button_par_1 = Button(canvas, text="Selecionar parâmetros", command = lambda:select_par_PBS(canvas, PP_entry.get(), PPI_entry.get(), T_entry.get(), IPI_entry.get(), IBI_entry.get(), dur_entry.get()))
button_par_1.place(relx=0, rely=0.775, relwidth=1, relheight=0.05)
if (canvas==canvas1):
prot1 = 'pb'
prot1 = "PBS"
if (canvas==canvas2):
prot2 = 'pb'
prot2 = "PBS"
if (canvas==canvas3):
prot3 = 'pb'
prot3 = "PBS"
#Função para interface de seleção dos parâmetros de protocolo Basal unipolar
def select_par_basal(canvas, T, IPI, ITI, dur):
......@@ -437,22 +439,40 @@ def detect_arduino():
global arduino
arduino=serial.Serial(Arduino_ports[0].device,9600, timeout=2)
writeToLog("Conexão com Arduino estabelecida.")
time.sleep(1)
arduino.write(b'p')
arduino.write(b'b')
time.sleep(1)
arduino.close()
except:
writeToLog("Problema na conexão com Arduino. Reconectar USB.")
#Função de envio de dados para Arduino
def enviar_arduino():
def send_protocol():
try:
arduino=serial.Serial(Arduino_ports[0].device,9600, timeout=2)
time.sleep(1)
arduino.write(b'p')
if(prot1 == "Basal Unipolar"):
arduino.write(b'b')
elif(prot1 == "TBS Unipolar"):
arduino.write(b't')
elif(prot1 == "PBS"):
arduino.write(b'p')
else:
writeToLog("Problema no envio. Defina os protocolos desejados.")
arduino.close()
writeToLog("Protocolos enviados e iniciados com sucesso.")
except:
writeToLog("Não foi possível enviar. Problema na conexão com Arduino ou protocolos indefinidos.")
#Função de interrupção de protocolos
def interrupt_protocol():
try:
arduino=serial.Serial(Arduino_ports[0].device,9600, timeout=2)
time.sleep(1)
arduino.write(b'd')
arduino.write(b'd')
arduino.close()
writeToLog("Protocolos interrompidos.")
except:
writeToLog("Não foi possível enviar. Problema na conexão com Arduino.")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment