From 083767f626f91dd587dcfbd1ce6dc517a37dbf6c Mon Sep 17 00:00:00 2001 From: Musab Erdem Date: Thu, 18 Jul 2024 10:20:21 +0200 Subject: [PATCH] optimierung --- main.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 77d8dce..840f8cb 100644 --- a/main.py +++ b/main.py @@ -439,6 +439,11 @@ class ArduinoGUI: self.csv_writer.writerow([formatted_time, formatted_angle, formatted_setpoint, formatted_torque, formatted_output]) + + + except Exception as e: + print(e) + if self.ser: if self.ser.in_waiting: @@ -458,7 +463,6 @@ class ArduinoGUI: try: pass self.connect_lsp() - except Exception as e: print(e) @@ -466,7 +470,26 @@ class ArduinoGUI: def lsp_communication_loop(self): while self.running: - pass + if self.ser: + if self.ser.in_waiting: + try: + command = self.ser.readline().decode(errors='ignore').strip() + print(command) + if command == 'a': + message = f"{self.current_angle};{self.current_torque};{self.analogInput};{self.currentSetpoint};{self.currentOutput}\n" + self.ser.write(message.encode()) + time.sleep(0.1) + while self.ser.out_waiting: + pass + except Exception as e: + print(e) + #self.ser.write(b'Hallo\n') + else : + try: + pass + self.connect_lsp() + except Exception as e: + print(e) def send_pid_parameters(self):