forked from awendt/pyrelacs
adding logging
This commit is contained in:
parent
638cf4995e
commit
d2cd4f5c02
23
:w
Normal file
23
:w
Normal 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)
|
||||||
|
|
@ -2,19 +2,28 @@ import uldaq
|
|||||||
from IPython import embed
|
from IPython import embed
|
||||||
import typer
|
import typer
|
||||||
|
|
||||||
|
from pyrelacs.util.logging import config_logging
|
||||||
|
|
||||||
def connect():
|
log = config_logging()
|
||||||
try:
|
|
||||||
|
class ReadData():
|
||||||
|
def __init__(self) -> None:
|
||||||
devices = uldaq.get_daq_device_inventory(uldaq.InterfaceType.USB)
|
devices = uldaq.get_daq_device_inventory(uldaq.InterfaceType.USB)
|
||||||
daq_device = uldaq.DaqDevice(devices[0])
|
log.debug(f"Found daq devices {len(devices)}, connecting to the first one")
|
||||||
daq_device.connect()
|
self.daq_device = uldaq.DaqDevice(devices[0])
|
||||||
print(f"Connected to daq_device {devices[0].product_name}")
|
self.daq_device.connect()
|
||||||
print(f"Connected to daq_device {daq_device.is_connected()}")
|
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()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
except uldaq.ULException as e:
|
|
||||||
print('\n', e)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
typer.run(connect)
|
daq_input = Input_daq()
|
||||||
|
|
||||||
|
16
pyrelacs/output.py
Normal file
16
pyrelacs/output.py
Normal 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
25
pyrelacs/util/logging.py
Normal 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
|
Loading…
Reference in New Issue
Block a user