From a49f98ba631bd6cc035bec352061d9201278c58b Mon Sep 17 00:00:00 2001 From: Markus Koller Date: Fri, 24 Feb 2023 11:45:33 +0100 Subject: [PATCH] Updating canvas slows down loop. only increment it if new field is set Takes ca 50-100ms --- src/csv_threading.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/csv_threading.py b/src/csv_threading.py index b88789f..2a111d2 100644 --- a/src/csv_threading.py +++ b/src/csv_threading.py @@ -95,15 +95,6 @@ class ExecCSVThread(Thread): t = time.time() - t_zero # get time relative to start of run target_t = array[i, 0] # Target execution time of data point - # Update figure - try: - for j in range(4): - avx_lines[j].set_data([t, t], [0, 1]) - #print("The next line might crash the programm, outcomment if necessary") - parent.plot_canvas.draw() # equivalent to matplotlib.show() - except DeviceAccessError as e: - ui_print("Failed to update figure: ", e) - if t >= target_t: # time for this row has come field_vec = array[i, 1:4] # extract desired field vector ui_print("[{:5.3f}s] B=[{:.1f}, {:.1f}, {:.1f}]\u03BCT for t={:.2f}s".format(t, @@ -119,11 +110,22 @@ class ExecCSVThread(Thread): logger = controller.pages[ui.ConfigureLogging] # get object of logging configurator if logger.event_logging: # data should be logged when test bench is commanded logger.log_datapoint() # log data + + # Update figure + try: + for j in range(4): + avx_lines[j].set_data([t, t], [0, 1]) + # print("The next line might crash the programm, outcomment if necessary") + parent.plot_canvas.draw() # equivalent to matplotlib.show() + except DeviceAccessError as e: + ui_print("Failed to update figure: ", e) + i = i + 1 # next row elif t <= target_t - delay - 0.02: # is there enough time to sleep before the next row? time.sleep(delay) # sleep to give other threads time to run + ui_print("Sequence executed, powering down channels.")