def do_scan(self): """Does a scan of an analog output while recording an analog input. It doesn't take any arguments, it relies on having the proper properties set in the dictionary properties['Scan'] """ self.running_scan = True start = Q_(self.properties['Scan']['start']) stop = Q_(self.properties['Scan']['stop']) step = Q_(self.properties['Scan']['step']) port_in = self.properties['Scan']['port_in'] port_out = self.properties['Scan']['port_out'] delay = Q_(self.properties['Scan']['delay']) self.stop_scan = False units = start.u stop = stop.to(units) num_points = (stop - start) / step num_points = int(num_points.m_as('')) scan = np.linspace(start, stop, num_points + 1) self.xdata_scan = scan self.ydata_scan = np.zeros((num_points + 1)) i = 0 for value in scan: if self.stop_scan: break value = value * units self.daq.set_analog_value(port_out, value) sleep(delay.m_as('s')) data = self.read_analog(port_in).m_as('V') self.ydata_scan[i] = data i += 1 self.running_scan = False
def do_scan(self): """Does a scan of an analog output while recording an analog input. It doesn't take any arguments, it relies on having the proper properties set in the dictionary properties['Scan'] """ if self.running_scan: raise Warning('Trying to start a second scan') start = Q_(self.properties['Scan']['start']) stop = Q_(self.properties['Scan']['stop']) step = Q_(self.properties['Scan']['step']) channel_in = self.properties['Scan']['channel_in'] channel_out = self.properties['Scan']['channel_out'] delay = Q_(self.properties['Scan']['delay']) units = start.u stop = stop.to(units) num_points = (stop - start) / step num_points = round(num_points.m_as('')) + 1 scan = np.linspace(start, stop, num_points) * units self.xdata_scan = scan self.ydata_scan = np.zeros(num_points) * units i = 0 self.running_scan = True for value in scan: self.daq.set_analog_value(int(channel_out), value) sleep(delay.m_as('s')) self.ydata_scan[i] = self.daq.get_analog_value(int(channel_in)) i += 1 self.running_scan = False
def monitor_signal(self): """Monitors a signal in a specific port. Doesn't take any parameters, it assumes there is well-configured dictionary called self.properties['Monitor'] """ delay = Q_(self.properties['Monitor']['time_resolution']) total_time = Q_(self.properties['Monitor']['total_time']).m_as('s') self.xdata = np.zeros((round(total_time / delay.m_as('s')))) self.delta_x = delay.m_as('s') self.ydata = np.zeros(int(total_time / delay.m_as('s'))) self.t0 = time() while not self.stop_monitor: self.ydata = np.roll(self.ydata, -1) self.ydata[-1] = self.read_analog(1).m_as('V') self.xdata = np.roll(self.xdata, -1) self.xdata[-1] = time() - self.t0 # self.xdata[-2] + self.delta_x sleep(delay.m_as('s'))
def start_scan(self): """Starts the scan as defined in the Experiment model. Gets the parameters from the GUI, i.e.: it gets the input port and delay, the output port and range. It updates the plot with the proper units and ranges and creates a worker thread for running the scan. A timer will be responsible for updating the values into the plot. """ if self.running_scan: print('Scan already running') return self.running_scan = True self.experiment.properties['Scan'].update({ 'port_out': int(self.outPortLine.text()), 'start': Q_(self.outStartLine.text()), 'stop': Q_(self.outStopLine.text()), 'step': Q_(self.outStepLine.text()), 'port_in': int(self.inPortLine.text()), 'delay': Q_(self.inDelayLine.text()), }) xlabel = self.experiment.properties['Scan']['port_out'] units = self.experiment.properties['Scan']['start'].u ylabel = self.experiment.properties['Scan']['port_in'] self.main_plot.setLabel('bottom', 'Port: {}'.format(xlabel), units=units) self.main_plot.setLabel('left', 'Port: {}'.format(ylabel), units='V') self.worker_thread = WorkThread(self.experiment.do_scan) self.worker_thread.finished.connect(self.worker_thread.deleteLater) self.worker_thread.finished.connect(self.stop_scan) self.worker_thread.start() refresh_time = Q_(self.experiment.properties['Scan']['refresh_time']) self.update_timer.start(refresh_time.m_as('ms'))
def start_monitor(self): """Starts a monitor in a separated Worker Thread. There will be a delay for the update of the plot. """ if self.running_monitor: print('Monitor already running') return self.running_monitor = True delay = Q_(self.delayLine.text()) self.experiment.properties['time_resolution'] = delay self.worker_thread = WorkThread(self.experiment.monitor_signal) self.worker_thread.start() refresh_time = Q_( self.experiment.properties['Monitor']['refresh_time']) self.update_timer.start(refresh_time.m_as('ms'))