def do_scan(self): start = ur(self.config['Scan']['start']).m_as('V') stop = ur(self.config['Scan']['stop']).m_as('V') num_steps = int(self.config['Scan']['num_steps']) delay = ur(self.config['Scan']['delay']) self.scan_range = np.linspace(start, stop, num_steps) * ur('V') self.scan_data = np.zeros(num_steps) * ur('V') i = 0 for volt in self.scan_range: self.daq.set_voltage(self.config['Scan']['channel_out'], volt) measured_voltage = self.daq.get_voltage( self.config['Scan']['channel_in']) self.scan_data[i] = measured_voltage i += 1 sleep(delay.m_as('s'))
def do_scan(self): if self.is_running: print('Scan already running') return self.is_running = True start = ur(self.config['Scan']['start']).m_as('V') stop = ur(self.config['Scan']['stop']).m_as('V') num_steps = int(self.config['Scan']['num_steps']) delay = ur(self.config['Scan']['delay']) self.scan_range = np.linspace(start, stop, num_steps) * ur('V') self.scan_data = np.zeros(num_steps) * ur('V') i = 0 self.keep_running = True for volt in self.scan_range: if not self.keep_running: break self.daq.set_voltage(self.config['Scan']['channel_out'], volt) measured_voltage = self.daq.get_voltage( self.config['Scan']['channel_in']) self.scan_data[i] = measured_voltage i += 1 sleep(delay.m_as('s')) self.is_running = False
def get_voltage(self, channel): """ Retrieve the voltage from the device Parameters ---------- channel : int Channel number Returns ------- Quantity The voltage read """ voltage_bits = self.driver.get_analog_input(channel) voltage = voltage_bits * ur('3.3V') / 1023 return voltage
def finalize(self): """ Set the outputs to 0V and finalize the driver """ self.set_voltage(0, ur('0V')) self.set_voltage(1, ur('0V')) self.driver.finalize()
def initialize(self): """ Initialize the driver and sets the voltage on the outputs to 0 """ self.driver.initialize() self.set_voltage(0, ur('0V')) self.set_voltage(1, ur('0V'))
self.driver.set_analog_output(channel, value_int) def get_voltage(self, channel): """ Retrieve the voltage from the device Parameters ---------- channel : int Channel number Returns ------- Quantity The voltage read """ voltage_bits = self.driver.get_analog_input(channel) voltage = voltage_bits * ur('3.3V') / 1023 return voltage def __str__(self): return "Analog Daq" if __name__ == "__main__": daq = AnalogDaq('/dev/ttyACM0') daq.initialize() voltage = ur('3000mV') daq.set_voltage(0, voltage) input_volts = daq.get_voltage(0) print(input_volts) daq.finalize()
def __init__(self, config_file): self.config_file = config_file self.is_running = False # Variable to check if the scan is running self.scan_range = np.array([0]) * ur('V') self.scan_data = np.array([0]) * ur('V')
def initialize(self): self.driver.initialize() self.set_voltage(0, ur('0V')) self.set_voltage(1, ur('0V'))
def get_voltage(self, channel): voltage_bits = self.driver.get_analog_input(channel) voltage = voltage_bits * ur('3.3V') / 1023 return voltage
def finalize(self): self.set_voltage(0, ur('0V')) self.set_voltage(1, ur('0V')) self.driver.finalize()