2
0
forked from awendt/pyrelacs

adding logging

This commit is contained in:
wendtalexander 2024-09-17 07:57:00 +02:00
parent 638cf4995e
commit d2cd4f5c02
4 changed files with 83 additions and 10 deletions

23
:w Normal file
View File

@ -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)

View File

@ -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()

16
pyrelacs/output.py Normal file
View File

@ -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()

25
pyrelacs/util/logging.py Normal file
View File

@ -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