example of reading input
This commit is contained in:
		
							parent
							
								
									558e0de315
								
							
						
					
					
						commit
						0e0262a3af
					
				| @ -1,54 +1,28 @@ | |||||||
| from typing import Optional |  | ||||||
| 
 |  | ||||||
| import uldaq | import uldaq | ||||||
| from IPython import embed |  | ||||||
| import typer |  | ||||||
| from typing_extensions import Annotated |  | ||||||
| import matplotlib.pyplot as plt | import matplotlib.pyplot as plt | ||||||
| 
 | 
 | ||||||
| from pyrelacs.util.logging import config_logging | from pyrelacs.util.logging import config_logging | ||||||
|  | from .repos import Repos | ||||||
| 
 | 
 | ||||||
| log = config_logging() | log = config_logging() | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class ReadData: | class ReadData(Repos): | ||||||
|     def __init__(self) -> None: |     def __init__(self) -> None: | ||||||
|         devices = uldaq.get_daq_device_inventory(uldaq.InterfaceType.USB) |         super().__init__() | ||||||
|         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, channel: Annotated[Optional[int], typer.Argument()] = 0): |     def analog_in(self) -> None: | ||||||
|         # Get the Ananlog In device and Analog Info |         # Get the Ananlog In device and Analog Info | ||||||
|         ai_device = self.daq_device.get_ai_device() |         data = self.read_analog_daq( | ||||||
|         ai_info = ai_device.get_info() |             [0, 0], | ||||||
|         log.debug( |             10, | ||||||
|             f"Analog info,\n Channels available {ai_info.get_num_chans()}, \n Max Samplerate: {ai_info.get_max_scan_rate()}" |             3000.0, | ||||||
|         ) |         ) | ||||||
|         buffer_len = 1_000_000 |         plt.plot(data) | ||||||
|         buf = uldaq.create_float_buffer(1, buffer_len) |  | ||||||
| 
 |  | ||||||
|         er = ai_device.a_in_scan( |  | ||||||
|             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") |  | ||||||
| 
 |  | ||||||
|         self.daq_device.disconnect() |  | ||||||
|         self.daq_device.release() |  | ||||||
|         plt.plot(buf) |  | ||||||
|         plt.show() |         plt.show() | ||||||
|  |         self.disconnect_dac() | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| if __name__ == "__main__": | if __name__ == "__main__": | ||||||
|     daq_input = ReadData() |     daq_input = ReadData() | ||||||
|     typer.run(daq_input.read_analog_in) |     daq_input.analog_in() | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user