From d2cd4f5c0265642e7ee5f120da3692585b492e58 Mon Sep 17 00:00:00 2001 From: wendtalexander Date: Tue, 17 Sep 2024 07:57:00 +0200 Subject: [PATCH] adding logging --- :w | 23 +++++++++++++++++++++++ pyrelacs/input.py | 29 +++++++++++++++++++---------- pyrelacs/output.py | 16 ++++++++++++++++ pyrelacs/util/logging.py | 25 +++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 10 deletions(-) create mode 100644 :w create mode 100644 pyrelacs/output.py create mode 100644 pyrelacs/util/logging.py diff --git a/:w b/:w new file mode 100644 index 0000000..825cc45 --- /dev/null +++ b/:w @@ -0,0 +1,23 @@ +import uldaq +from IPython import embed +import typer + +class Input(): + def __init__(self) -> None: + pass + + def connect(self): + try: + devices = uldaq.get_daq_device_inventory(uldaq.InterfaceType.USB) + daq_device = uldaq.DaqDevice(devices[0]) + daq_device.connect() + print(f"Connected to daq_device {devices[0].product_name}") + print(f"Connected to daq_device {daq_device.is_connected()}") + + except uldaq.ULException as e: + print('\n', e) + + +if __name__ == '__main__': + typer.run(connect) + diff --git a/pyrelacs/input.py b/pyrelacs/input.py index dc20992..12a341a 100644 --- a/pyrelacs/input.py +++ b/pyrelacs/input.py @@ -2,19 +2,28 @@ import uldaq from IPython import embed import typer +from pyrelacs.util.logging import config_logging -def connect(): - try: +log = config_logging() + +class ReadData(): + def __init__(self) -> None: devices = uldaq.get_daq_device_inventory(uldaq.InterfaceType.USB) - daq_device = uldaq.DaqDevice(devices[0]) - daq_device.connect() - print(f"Connected to daq_device {devices[0].product_name}") - print(f"Connected to daq_device {daq_device.is_connected()}") - - except uldaq.ULException as e: - print('\n', e) + log.debug(f"Found daq devices {len(devices)}, connecting to the first one") + self.daq_device = uldaq.DaqDevice(devices[0]) + self.daq_device.connect() + log.debug("Connected") + + def read_analog_in(self): + # Get the Ananlog In device and Analog Info + ai_device = self.daq_device.get_ai_device() + ai_info = self.daq_device.get_info() + + + + if __name__ == '__main__': - typer.run(connect) + daq_input = Input_daq() diff --git a/pyrelacs/output.py b/pyrelacs/output.py new file mode 100644 index 0000000..f910ddb --- /dev/null +++ b/pyrelacs/output.py @@ -0,0 +1,16 @@ +import uldaq +from IPython import embed +import typer + +class Output_daq(): + def __init__(self) -> None: + devices = uldaq.get_daq_device_inventory(uldaq.InterfaceType.USB) + daq_device = uldaq.DaqDevice(devices[0]) + daq_device.connect() + + + + +if __name__ == '__main__': + daq_input = Input_daq() + diff --git a/pyrelacs/util/logging.py b/pyrelacs/util/logging.py new file mode 100644 index 0000000..156c52f --- /dev/null +++ b/pyrelacs/util/logging.py @@ -0,0 +1,25 @@ +import pathlib +import logging +from rich.logging import RichHandler + +logger = logging.getLogger("pyrelacs") + + +def config_logging(): + if logger.hasHandlers(): + logger.handlers.clear() + + stream_handler = RichHandler() + logger.setLevel(level="DEBUG") + stream_handler.setLevel(level="DEBUG") + + fmt_shell = "%(message)s" + + shell_formatter = logging.Formatter(fmt_shell) + + # here we hook everything together + stream_handler.setFormatter(shell_formatter) + + logger.addHandler(stream_handler) + + return logger