forked from zietzm/Helmholtz_Test_Bench
enabled and added callable status display updates
This commit is contained in:
+11
-4
@@ -90,6 +90,8 @@ class ManualMode(Frame):
|
||||
def __init__(self, parent, controller):
|
||||
Frame.__init__(self, parent)
|
||||
|
||||
self.controller = controller # object on which mainloop() is running, usually main window
|
||||
|
||||
self.grid_rowconfigure(ALL, weight=1)
|
||||
self.grid_columnconfigure(ALL, weight=1)
|
||||
|
||||
@@ -230,6 +232,7 @@ class ManualMode(Frame):
|
||||
vector[i] = float(var.get())
|
||||
i = i + 1
|
||||
function_to_call(vector) # call function
|
||||
self.controller.StatusDisplay.update_labels() # update status display after change
|
||||
|
||||
def execute_field(self, vector):
|
||||
func.ui_print("field executing", vector)
|
||||
@@ -512,6 +515,7 @@ class ExecuteCSVMode(Frame):
|
||||
|
||||
def __init__(self, parent, controller):
|
||||
Frame.__init__(self, parent)
|
||||
self.controller = controller # object on which mainloop() is running, usually main window
|
||||
|
||||
# Functional init:
|
||||
self.sequence_array = None # array containing the values from the csv file
|
||||
@@ -580,7 +584,7 @@ class ExecuteCSVMode(Frame):
|
||||
# g.threadLock = threading.Lock()
|
||||
# create separate thread to run sequence execution in:
|
||||
g.running = True
|
||||
csv_thread = csv.ExecCSVThread("CSV_Thread", self.sequence_array, self)
|
||||
csv_thread = csv.ExecCSVThread("CSV_Thread", self.sequence_array, self, self.controller)
|
||||
csv_thread.start() # start thread
|
||||
|
||||
def stop_run(self):
|
||||
@@ -637,9 +641,13 @@ class StatusDisplay(Frame):
|
||||
col = col + 1
|
||||
# rowCounter = rowCounter + self.rowNo # increase row counter to place future stuff below this
|
||||
|
||||
self.update_labels(controller)
|
||||
self.continuous_label_update(controller, 500) # initiate regular value updates (ms)
|
||||
|
||||
def update_labels(self, controller):
|
||||
def continuous_label_update(self, controller, interval): # update display values in regular intervals
|
||||
self.update_labels()
|
||||
controller.after(interval, lambda: self.continuous_label_update(controller, interval))
|
||||
|
||||
def update_labels(self):
|
||||
g.ARDUINO.update_status_info()
|
||||
i = 0
|
||||
for axis in g.AXES:
|
||||
@@ -660,7 +668,6 @@ class StatusDisplay(Frame):
|
||||
self.label_dict["Target Current:"][i].set("%0.3f A" % axis.target_current)
|
||||
self.label_dict["Inverted:"][i].set(axis.polarity_switched)
|
||||
i = i + 1
|
||||
controller.after(500, lambda: self.update_labels(controller))
|
||||
|
||||
|
||||
class OutputConsole(Frame): # console to print stuff in, similar to standard python output
|
||||
|
||||
+7
-4
@@ -6,19 +6,20 @@ import globals as g
|
||||
|
||||
|
||||
class ExecCSVThread(Thread):
|
||||
def __init__(self, threadID, array, parent):
|
||||
def __init__(self, threadID, array, parent, controller):
|
||||
# ToDo: comments
|
||||
Thread.__init__(self)
|
||||
|
||||
self.threadID = threadID
|
||||
self.array = array # numpy array containing data from csv to be executed
|
||||
self.parent = parent
|
||||
self.controller = controller # object on which mainloop() is running, usually main window
|
||||
|
||||
def run(self):
|
||||
func.ui_print("Starting Sequence Execution...")
|
||||
# g.threadLock.acquire() # Get lock to synchronize threads
|
||||
# ToDo: add locking/synchronization? Works without so far but might be more robust
|
||||
execute_sequence(self.array, 0.1)
|
||||
execute_sequence(self.array, 0.1, self.controller)
|
||||
self.parent.running = False
|
||||
# reset buttons:
|
||||
self.parent.select_file_button["state"] = "normal"
|
||||
@@ -26,7 +27,7 @@ class ExecCSVThread(Thread):
|
||||
self.parent.stop_button["state"] = "disabled"
|
||||
|
||||
|
||||
def execute_sequence(array, delay): # runs through array containing times and desired field vectors
|
||||
def execute_sequence(array, delay, controller): # runs through array containing times and desired field vectors
|
||||
# array format: [time (s), xField (T), yField (T), zField (T)]
|
||||
# decimal commas
|
||||
# all times in seconds
|
||||
@@ -41,8 +42,10 @@ def execute_sequence(array, delay): # runs through array containing times and d
|
||||
% (time.time()-t_zero, array[i, 0]), field_vec*1e6, "\u03BCT")
|
||||
func.set_field_simple(field_vec) # send field vector to test stand # ToDo!: reset to set_field()
|
||||
func.ui_print(time.time()-t_zero)
|
||||
controller.StatusDisplay.update_labels() # update status display after change
|
||||
i = i + 1 # next row
|
||||
elif t >= array[i, 0] - delay - 0.02: # not enough time to sleep
|
||||
|
||||
elif t >= array[i, 0] - delay - 0.02: # next change time is close, not enough time to sleep
|
||||
pass
|
||||
else: # sleep to give other threads time to run
|
||||
time.sleep(delay)
|
||||
|
||||
Reference in New Issue
Block a user