From 9c0c919991afb75e0c0825b7380c6827036621e4 Mon Sep 17 00:00:00 2001 From: CPD Date: Wed, 12 Mar 2025 16:44:43 +0100 Subject: [PATCH] Revert "Add logging" This reverts commit bbd654fa2f1598aa698769f708f3df7fba9b66be. --- cpdctrl/measurement.py | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/cpdctrl/measurement.py b/cpdctrl/measurement.py index 21314e1..2d3da9d 100644 --- a/cpdctrl/measurement.py +++ b/cpdctrl/measurement.py @@ -13,9 +13,6 @@ import time import datetime from queue import Queue -import logging -log = logging.getLogger(__name__) - def measure( vm_dev: VoltageMeasurementDevice, led_dev: LedControlDevice, @@ -94,17 +91,13 @@ def measure( i = 0 led_val = led_script.start() t_iter_start = time.time() - while True: - # using while True and if, to be able to log the stop reason - if max_measurements is not None and i >= max_measurements: - log.info(f"Reached maximum number of measurements ({i}{max_measurements}), stopping measurement") - break + while max_measurements is None or i < max_measurements: # 1) read value(s) if use_buffer: try: values = vm_dev.buffer_read_new_values() except ValueError as e: - # print(f"Error in buffer measurement {i}:", e) + print(f"Error in buffer measurement {i}:", e) values = [] else: values = [vm_dev.read_value()] @@ -117,7 +110,7 @@ def measure( current_data = (i, tval, vval, led_val) data.add_data(*current_data) # 3) write data - if verbose: print(f"n = {i:6d}, t = {tval: .2f} s, U = {vval: .5f} V, LED = {led_val:03}%" + " "*10, end='\r') + print(f"n = {i:6d}, t = {tval: .2f} s, U = {vval: .5f} V, LED = {led_val:03}%" + " "*10, end='\r') if flush_after is not None and (i+1) % flush_after == 0: data.flush(verbose=verbose) # if a queue was given, put the data @@ -129,16 +122,15 @@ def measure( if command_queue is not None and command_queue.qsize() > 0: recv = command_queue.get(block=False) if recv == "stop": - log.info(f"Received 'stop', stopping measuremetn") break elif type(recv) == tuple and recv[0] == "led_script": led_script = recv[1] else: - log.error(f"Received invalid message: '{recv}'") + print(f"Received invalid message: '{recv}'") # 4) sleep - # subtract the execution time from the sleep time for a more - # accurate frequency + # substract the execution time from the sleep time for a more + # acurate frequency dt_sleep = delta_t - (time.time() - t_iter_start) if dt_sleep > 0: # print(f"Sleeping for {dt_sleep}") @@ -146,7 +138,7 @@ def measure( t_iter_start = time.time() # 5) update LED if stop_on_script_end and led_script.is_done(t_iter_start): - log.info("Reached led script end, stopping measurement") + if verbose: print("Reached script end") break new_led_val = led_script.get_state(t_iter_start) if new_led_val != led_val: @@ -154,12 +146,11 @@ def measure( led_dev.set_level(new_led_val) led_val = new_led_val except Exception as e: - log.error("Error setting led to {new_led_val}%: {e}") + print(f"Error setting led to {new_led_val}%:") + print(e) except KeyboardInterrupt: - log.info("Keyboard interrupt, stopping") - except Exception as e: - log.critical(f"Unexpected error, stopping. Error: {e}") + pass if add_measurement_info_to_metadata: data.metadata["measurement_time_stop"] = get_time() # Write again after having updated the stop time