forked from awendt/pyrelacs
		
	
		
			
				
	
	
		
			52 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			52 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
import ctypes
 | 
						|
import time
 | 
						|
 | 
						|
import uldaq
 | 
						|
from IPython import embed
 | 
						|
from pyrelacs.repros.repos import Repos
 | 
						|
from pyrelacs.util.logging import config_logging
 | 
						|
import numpy as np
 | 
						|
import matplotlib.pyplot as plt
 | 
						|
 | 
						|
log = config_logging()
 | 
						|
 | 
						|
 | 
						|
class Calibration(Repos):
 | 
						|
    def __init__(self) -> None:
 | 
						|
        super().__init__()
 | 
						|
 | 
						|
    def run_calibration(self):
 | 
						|
        # Stimulus
 | 
						|
        time = np.arange(0, DURATION, 1 / SAMPLERATE)
 | 
						|
        data = AMPLITUDE * np.sin(2 * np.pi * SINFREQ * time)
 | 
						|
        # sending stimulus
 | 
						|
 | 
						|
        stim, ao_device = self.write_analog_dac(
 | 
						|
            data, [0, 0], SAMPLERATE, ScanOption=uldaq.ScanOption.EXTTRIGGER
 | 
						|
        )
 | 
						|
 | 
						|
        # read_data = self.read_analog_daq(
 | 
						|
        #     [0, 1], DURATION, SAMPLERATE, ScanOption=uldaq.ScanOption.EXTTRIGGER
 | 
						|
        # )
 | 
						|
 | 
						|
        # trigger the 0 channel to start the aqcuisition
 | 
						|
        self.write_bit(channel=0, bit=1)
 | 
						|
        try:
 | 
						|
            ao_device.scan_wait(uldaq.WaitType.WAIT_UNTIL_DONE, 15)
 | 
						|
        except uldaq.ul_exception.ULException:
 | 
						|
            log.debug("Operation timed out")
 | 
						|
            self.write_bit(channel=0, bit=0)
 | 
						|
            self.disconnect_dac()
 | 
						|
            self.connect_dac()
 | 
						|
            self.set_analog_to_zero()
 | 
						|
 | 
						|
 | 
						|
if __name__ == "__main__":
 | 
						|
    SAMPLERATE = 40_000.0
 | 
						|
    DURATION = 10
 | 
						|
    AMPLITUDE = 1
 | 
						|
    SINFREQ = 100
 | 
						|
    daq_input = Calibration()
 | 
						|
    # daq_input.run_calibration()
 | 
						|
    daq_input.attenuator()
 |