Revert "Add logging"

This reverts commit bbd654fa2f1598aa698769f708f3df7fba9b66be.
This commit is contained in:
CPD 2025-03-12 16:44:43 +01:00
parent 58480a1067
commit 9c0c919991

View File

@ -13,9 +13,6 @@ import time
import datetime import datetime
from queue import Queue from queue import Queue
import logging
log = logging.getLogger(__name__)
def measure( def measure(
vm_dev: VoltageMeasurementDevice, vm_dev: VoltageMeasurementDevice,
led_dev: LedControlDevice, led_dev: LedControlDevice,
@ -94,17 +91,13 @@ def measure(
i = 0 i = 0
led_val = led_script.start() led_val = led_script.start()
t_iter_start = time.time() t_iter_start = time.time()
while True: while max_measurements is None or i < max_measurements:
# 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
# 1) read value(s) # 1) read value(s)
if use_buffer: if use_buffer:
try: try:
values = vm_dev.buffer_read_new_values() values = vm_dev.buffer_read_new_values()
except ValueError as e: except ValueError as e:
# print(f"Error in buffer measurement {i}:", e) print(f"Error in buffer measurement {i}:", e)
values = [] values = []
else: else:
values = [vm_dev.read_value()] values = [vm_dev.read_value()]
@ -117,7 +110,7 @@ def measure(
current_data = (i, tval, vval, led_val) current_data = (i, tval, vval, led_val)
data.add_data(*current_data) data.add_data(*current_data)
# 3) write 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: if flush_after is not None and (i+1) % flush_after == 0:
data.flush(verbose=verbose) data.flush(verbose=verbose)
# if a queue was given, put the data # 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: if command_queue is not None and command_queue.qsize() > 0:
recv = command_queue.get(block=False) recv = command_queue.get(block=False)
if recv == "stop": if recv == "stop":
log.info(f"Received 'stop', stopping measuremetn")
break break
elif type(recv) == tuple and recv[0] == "led_script": elif type(recv) == tuple and recv[0] == "led_script":
led_script = recv[1] led_script = recv[1]
else: else:
log.error(f"Received invalid message: '{recv}'") print(f"Received invalid message: '{recv}'")
# 4) sleep # 4) sleep
# subtract the execution time from the sleep time for a more # substract the execution time from the sleep time for a more
# accurate frequency # acurate frequency
dt_sleep = delta_t - (time.time() - t_iter_start) dt_sleep = delta_t - (time.time() - t_iter_start)
if dt_sleep > 0: if dt_sleep > 0:
# print(f"Sleeping for {dt_sleep}") # print(f"Sleeping for {dt_sleep}")
@ -146,7 +138,7 @@ def measure(
t_iter_start = time.time() t_iter_start = time.time()
# 5) update LED # 5) update LED
if stop_on_script_end and led_script.is_done(t_iter_start): 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 break
new_led_val = led_script.get_state(t_iter_start) new_led_val = led_script.get_state(t_iter_start)
if new_led_val != led_val: if new_led_val != led_val:
@ -154,12 +146,11 @@ def measure(
led_dev.set_level(new_led_val) led_dev.set_level(new_led_val)
led_val = new_led_val led_val = new_led_val
except Exception as e: 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: except KeyboardInterrupt:
log.info("Keyboard interrupt, stopping") pass
except Exception as e:
log.critical(f"Unexpected error, stopping. Error: {e}")
if add_measurement_info_to_metadata: if add_measurement_info_to_metadata:
data.metadata["measurement_time_stop"] = get_time() data.metadata["measurement_time_stop"] = get_time()
# Write again after having updated the stop time # Write again after having updated the stop time