def do_scan(self): if self.scan_running: print('Scan already running') return # raise Exception("Scan already running") self.scan_running = True start = ur(self.params['Scan']['start']) stop = ur(self.params['Scan']['stop']) step = ur(self.params['Scan']['step']) self.voltages = np.arange(start.m_as('V'), stop.m_as('V') + step.m_as('V'), step.m_as('V')) self.currents = np.zeros((len(self.voltages))) for i in range(len(self.voltages)): channel = self.params['Scan']['channel_out'] self.daq.set_voltage(channel, self.voltages[i] * ur('V')) channel_in = self.params['Scan']['channel_in'] current = self.daq.read_current(channel_in) self.currents[i] = current.m_as('A') delay = ur(self.params['Scan']['delay']) time.sleep(delay.m_as('s')) self.scan_running = False
def check_start(self): start = self.start_line.text() try: if ur(start) > ur('3.3V') or ur(start) < ur('0V'): print(f'Start can\'t be {start}') self.start_button.setEnabled(False) else: self.start_button.setEnabled(True) except Exception as e: print(e) self.start_button.setEnabled(False)
def monitor_signal(self): if self.is_running: raise Exception('Device already running') self.monitor_currents = np.zeros(self.config['monitor']['samples']) * ur('mA') resistance = ur(self.config['experiment']['resistance']) self.keep_running = True self.is_running = True while self.keep_running: new_current = self.daq.read_analog(self.config['monitor']['channel_in'])/resistance self.monitor_currents = np.roll(self.monitor_currents, -1) self.monitor_currents[-1] = new_current.m_as('mA') self.is_running = False
def update_gui(self): start = self.start_line.text() stop = self.stop_line.text() if ur(start) > ur('3.3V') or ur(stop) > ur('3.3V') or self.experiment.is_running: self.start_button.setEnabled(False) if ur(start) <= ur('3.3V') and ur(stop) <= ur('3.3V') and not self.experiment.is_running: self.start_button.setEnabled(True)
def load_daq(self): port = self.params['Params']['port'] resistance = ur(self.params['Params']['resistance']) if self.params['Params']['device_type'] == 'real': self.daq = AnalogDaq(port, resistance) elif self.params['Params']['device_type'] == 'dummy': self.daq = DummyDaq(port, resistance) else: raise Exception('no Daq Device named in Config')
def load_daq(self): port = self.params['Params']['port'] resistance = ur(self.params['Params']['resistance']) if self.params['Params']['device_type'] == 'real': self.daq = AnalogDaq(port, resistance) elif self.params['Params']['device_type'] == 'dummy': self.daq = dummyDaq(port, resistance) else: raise Exception('Daq device not recognized')
def do_scan(self): if self.is_running: raise Exception('Scan already running') start = ur(self.config['scan']['start']) stop = ur(self.config['scan']['stop']) num_steps = int(self.config['scan']['num_steps']) self.volts = np.linspace(start.m_as('V'), stop.m_as('V'), num_steps) * ur('V') self.currents = np.zeros(num_steps) * ur('A') resistance = ur(self.config['experiment']['resistance']) delay = ur(self.config['scan']['delay']).m_as('s') self.keep_running = True self.i = 0 self.is_running = True for volt in self.volts: self.daq.set_analog(self.config['scan']['channel_out'], volt) current = self.daq.read_analog(self.config['scan']['channel_in'])/resistance # self.currents.append(current.to('mA')) self.currents[self.i] = current.to('A') self.i += 1 sleep(delay) if not self.keep_running: print('Scan stopped') break self.is_running = False
def do_scan(self): if self.is_running: return 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']) self.scan_range = np.linspace(start, stop, num_steps) * ur('V') self.scan_data = np.zeros(num_steps) self.i = 0 self.keep_running = True self.is_running = True for volt in self.scan_range: volt = volt self.daq.set_voltage(self.config['scan']['channel_out'], volt) measured_voltage = self.daq.get_voltage( self.config['scan']['channel_in']) current = measured_voltage / ur(self.config['scan']['resistance']) self.scan_data[self.i] = current.m_as('mA') self.i += 1 if not self.keep_running: break self.is_running = False
def monitor_signal(self): if self.is_running: return self.monitor_data = np.zeros(self.config['monitor']['num_steps']) self.keep_monitor_running = True self.is_running = True while self.keep_monitor_running: measured_voltage = self.daq.get_voltage( self.config['monitor']['channel_in']) self.monitor_data = np.roll(self.monitor_data, -1) self.monitor_data[-1] = measured_voltage.m_as('mV') sleep_time = ur(self.config['monitor']['time_step']) time.sleep(sleep_time.m_as('s')) self.is_running = False
def read_analog(self, channel): query_string = 'IN:CH{}'.format(channel) value_bits = int(self.driver.query(query_string)) value_volts = value_bits / 1024 * ur('3.3V') return value_volts
def read_analog(self, channel): return np.random.random() * ur('V')
def finalize(self): self.set_voltage(0, ur('0V')) self.driver.close()
def get_voltage(self, channel): voltage_bits = self.driver.get_analog_input(channel) voltage = voltage_bits * ur('3.3V') / 1023 return voltage
def set_voltage(self, channel, voltage): voltage_bits = voltage / ur('3.3V') * 4095 voltage_bits = int(voltage_bits.m_as('')) self.driver.set_analog_output(channel, voltage_bits)
class AnalogDaq: def __init__(self, port): self.port = port self.driver = None def initialize(self): self.driver = Device(self.port) def set_voltage(self, channel, voltage): voltage_bits = voltage / ur('3.3V') * 4095 voltage_bits = int(voltage_bits.m_as('')) self.driver.set_analog_output(channel, voltage_bits) 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.driver.close() if __name__ == "__main__": daq = AnalogDaq('/dev/ttyACM0') daq.initialize() voltage = ur('3.V') daq.set_voltage(0, voltage) input_volts = daq.get_voltage(0) print(input_volts) daq.finalize()
def load_daq(self): port = self.params['Params']['port'] resistance = ur(self.params['Params']['resistance']) self.daq = AnalogDaq(port, resistance)
def read_current(self, channel): voltage = self.driver.get_analog_value(channel) voltage = voltage/1023*ur('3.3V') current = voltage/self.resistance return current
def read_current(self, channel): current = np.random.randn() * ur('A') return current
from controller.simple_daq import Device from model import ur class RealDaq: def __init__(self, port): self.driver = Device(port) def idn(self): return self.driver.query('IDN') def read_analog(self, channel): query_string = 'IN:CH{}'.format(channel) value_bits = int(self.driver.query(query_string)) value_volts = value_bits / 1024 * ur('3.3V') return value_volts def set_analog(self, channel, value): value = int(value.m_as('V') / 3.3 * 4095) self.driver.set_analog(channel, value) if __name__ == '__main__': daq = RealDaq('COM9') daq.set_analog(0, ur('3.3V')) print(daq.get_analog_value(0))