From d546293e9c561930644ebfcbb41fa64464ecd555 Mon Sep 17 00:00:00 2001 From: Simon Frei Date: Mon, 13 Mar 2023 22:30:38 +0100 Subject: [PATCH] remove timeout --- ASYD_Safety/ReadData.py | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/ASYD_Safety/ReadData.py b/ASYD_Safety/ReadData.py index bd69861..f30512e 100644 --- a/ASYD_Safety/ReadData.py +++ b/ASYD_Safety/ReadData.py @@ -109,21 +109,27 @@ import numpy as np def f(conn,q): ongoing = True reading = False + serialPort = serial.Serial(port='COM7',baudrate=115200,timeout=1) while ongoing: if conn.poll(): rec = conn.recv() if rec == 'start': reading = True - serialPort = serial.Serial(port='COM7',baudrate=115200,timeout=1) + #if not serialPort.isOpen(): + # print('open serial port') + #serialPort.close() + # serialPort = serial.Serial(port='COM7',baudrate=115200,timeout=1) + #else: + # print('already open') if rec == 'stop': reading = False - serialPort.close() + # serialPort.close() if rec == 'kill': serialPort.close() #print(data) ongoing=False - if reading: - if serialPort.inWaiting() > 0: + if serialPort.inWaiting() > 0: + if reading: msg = serialPort.readline() try: msg = msg.decode("Ascii") @@ -131,7 +137,9 @@ def f(conn,q): print("failed") if msg.startswith("X"): q.put(msg) - time.sleep(0.05) + else: + serialPort.read_all() + #time.sleep(0.001) conn.close() def buttonPressed(button, conn,q): @@ -143,13 +151,14 @@ def buttonPressed(button, conn,q): dString = dString.rstrip("\r\n") tmp = dString.split('\t') d = {} + print(tmp) for elem in tmp: tmp1 = elem.split(':') d[tmp1[0]] = int(tmp1[1]) data.append(d) df = pd.DataFrame(data) df['sqr'] = df.apply(lambda x: - np.sqrt(x['X']**2+x['Y']**2+x['Z']**2),axis=1) + np.sqrt(x['X']**2+x['Y']**2+x['Z']**2),axis=1) for l in window.pack_slaves(): if isinstance(l, tk.Canvas): l.destroy() @@ -157,7 +166,19 @@ def buttonPressed(button, conn,q): ax2 = figure.add_subplot(111) line = FigureCanvasTkAgg(figure,window) line.get_tk_widget().pack(side=tk.LEFT, fill=tk.BOTH) - df.plot(kind='line',legend=True,ax=ax2) + #ax2.hline(173,df.shape[0]) + #df.plot(kind='line',legend=True,ax=ax2, grid=True) + #df.plot.line(y=173) + ax2.plot(df['X'],'-b',label='X',) + ax2.plot(df['Y'],'-y',label='Y') + ax2.plot(df['Z'],'-g',label='Z') + ax2.plot(df['sqr'],color='black',label='sqr') + axl = ax2.twinx() + axl.plot(df['F'],'-*',label='Freefallcounter') + axl.legend() + ax2.grid() + ax2.axhline(y=173,color='red') + ax2.legend() def onClosing(): if tk.messagebox.askokcancel("Quit","Wanna quit?"):