2
0
forked from awendt/pyrelacs

updating input.py

This commit is contained in:
wendtalexander 2024-09-17 11:18:40 +02:00
parent 2c963c5085
commit dadd061147

View File

@ -1,12 +1,17 @@
from typing import Optional
import uldaq import uldaq
from IPython import embed from IPython import embed
import typer import typer
from typing_extensions import Annotated
import matplotlib.pyplot as plt
from pyrelacs.util.logging import config_logging from pyrelacs.util.logging import config_logging
log = config_logging() log = config_logging()
class ReadData():
class ReadData:
def __init__(self) -> None: def __init__(self) -> None:
devices = uldaq.get_daq_device_inventory(uldaq.InterfaceType.USB) devices = uldaq.get_daq_device_inventory(uldaq.InterfaceType.USB)
log.debug(f"Found daq devices {len(devices)}, connecting to the first one") log.debug(f"Found daq devices {len(devices)}, connecting to the first one")
@ -14,16 +19,35 @@ class ReadData():
self.daq_device.connect() self.daq_device.connect()
log.debug("Connected") log.debug("Connected")
def read_analog_in(self): def read_analog_in(self, channel: Annotated[Optional[int], typer.Argument()] = 0):
# Get the Ananlog In device and Analog Info # Get the Ananlog In device and Analog Info
ai_device = self.daq_device.get_ai_device() ai_device = self.daq_device.get_ai_device()
ai_info = self.daq_device.get_info() ai_info = ai_device.get_info()
log.debug(
f"Analog info,\n Channels available {ai_info.get_num_chans()}, \n Max Samplerate: {ai_info.get_max_scan_rate()}"
)
buffer_len = 1_000_000
buf = uldaq.create_float_buffer(1, buffer_len)
if __name__ == '__main__': er = ai_device.a_in_scan(
daq_input = Input_daq() 1,
1,
uldaq.AiInputMode.SINGLE_ENDED,
uldaq.Range.BIP10VOLTS,
buffer_len,
500_000,
uldaq.ScanOption.DEFAULTIO,
uldaq.AInScanFlag.DEFAULT,
data=buf,
)
ai_device.scan_wait(uldaq.WaitType.WAIT_UNTIL_DONE, timeout=-1)
log.debug("Scanning")
embed()
self.daq_device.disconnect()
self.daq_device.release()
if __name__ == "__main__":
daq_input = ReadData()
typer.run(daq_input.read_analog_in)