Ejemplo n.º 1
0
 def apply_new_values(self):
     """Formats the values in the form and emits a custom signal *propertiesChanged* including a
     dictionary of the values that are provided (changed or not).
     """
     new_values = {'port_monitor': int(self.portLine.text()),
                   'time_resolution': Q_(self.timeResolutionLine.text()),
                   'refresh_time': Q_(self.refreshTimeLine.text()),
                   'total_time': Q_(self.totalTimeLine.text()),}
     self.propertiesChanged.emit(new_values)
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
    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'))
Ejemplo n.º 5
0
    def get_analog_value(self, port):
        """Gets an analog value. They are going to represent a sine with frequency 250 points.

        :return Quantity: Voltage of the analog output
        """
        self.i += 1
        return np.sin(self.i / 10) * Q_('V')
Ejemplo n.º 6
0
    def __init__(self, experiment, parent=None):
        super().__init__(parent)

        self.experiment = experiment

        p = os.path.dirname(__file__)
        self.directory = p
        uic.loadUi(os.path.join(p, 'GUI/scan_window.ui'), self)

        self.update_timer = QtCore.QTimer()
        self.update_timer.timeout.connect(self.update_scan)

        self.main_plot = pg.PlotWidget()
        layout = self.centralwidget.layout()
        layout.addWidget(self.main_plot)
        self.ydata = np.zeros((0))
        self.xdata = np.zeros((0))
        self.p = self.main_plot.plot(self.xdata, self.ydata)

        self.startButton.clicked.connect(self.start_scan)
        self.stopButton.clicked.connect(self.stop_scan)

        self.outChannelLine.setText('{}'.format(
            self.experiment.properties['Scan']['channel_out']))
        self.outStartLine.setText('{:~}'.format(
            Q_(self.experiment.properties['Scan']['start'])))
        self.outStopLine.setText('{:~}'.format(
            Q_(self.experiment.properties['Scan']['stop'])))
        self.outStepLine.setText('{:~}'.format(
            Q_(self.experiment.properties['Scan']['step'])))

        self.inChannelLine.setText('{}'.format(
            self.experiment.properties['Scan']['channel_in']))
        self.inDelayLine.setText('{:~}'.format(
            Q_(self.experiment.properties['Scan']['delay'])))

        self.running_scan = False

        self.action_Save.triggered.connect(self.save_data)

        menubar = self.menuBar()
        self.scanMenu = menubar.addMenu('&Scan')
        self.start_scan_action = QtWidgets.QAction("Start Scan", self)
        self.start_scan_action.setShortcut('Ctrl+Shift+S')
        self.start_scan_action.setStatusTip('Start the scan')
        self.start_scan_action.triggered.connect(self.start_scan)
        self.scanMenu.addAction(self.start_scan_action)
Ejemplo n.º 7
0
    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'))
Ejemplo n.º 8
0
    def get_analog_value(self, channel):
        """ Reads the analog value from a specified port.

        :param int channel: Port number from which to read the value
        """
        query_string = 'IN:CH{}'.format(channel)
        value_bits = int(self.driver.query(query_string))
        value_volts = value_bits / 1024 * Q_('3.3V')
        return value_volts
Ejemplo n.º 9
0
 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'))
Ejemplo n.º 10
0
        :param int channel: Port number from which to read the value
        """
        query_string = 'IN:CH{}'.format(channel)
        value_bits = int(self.driver.query(query_string))
        value_volts = value_bits / 1024 * Q_('3.3V')
        return value_volts

    def set_analog_value(self, channel, value):
        """ Sets the analog value of a given port.

        :param int channel: Port on which to generate the output.
        :param Quantity value: Voltage to output.
        """
        value = int(value.m_as('V') / 3.3 * 4096)
        query_string = 'OUT:CH{}:{}'.format(channel, value)
        self.driver.write(query_string)


if __name__ == "__main__":
    from time import sleep
    d = AnalogDaq('/dev/ttyACM0')
    print(d.idn())
    off_voltage = Q_('0V')
    on_voltage = Q_('3.3V')
    for i in range(10):
        d.set_analog_value(0, on_voltage)
        print(d.get_analog_value(0))
        sleep(0.5)
        d.set_analog_value(0, off_voltage)
        print(d.get_analog_value(0))
        sleep(0.5)
Ejemplo n.º 11
0
        self.portLine.setText('{}'.format(experiment.properties['Monitor']['channel']))
        self.timeResolutionLine.setText(experiment.properties['Monitor']['time_resolution'])
        self.refreshTimeLine.setText(experiment.properties['Monitor']['refresh_time'])
        self.totalTimeLine.setText(experiment.properties['Monitor']['total_time'])

    def apply_new_values(self):
        """Formats the values in the form and emits a custom signal *propertiesChanged* including a
        dictionary of the values that are provided (changed or not).
        """
        new_values = {'port_monitor': int(self.portLine.text()),
                      'time_resolution': Q_(self.timeResolutionLine.text()),
                      'refresh_time': Q_(self.refreshTimeLine.text()),
                      'total_time': Q_(self.totalTimeLine.text()),}
        self.propertiesChanged.emit(new_values)

if __name__ == "__main__":
    import sys
    from PyQt5.Qt import QApplication
    ap = QApplication(sys.argv)
    from PythonForTheLab.Model.experiment.IV_measurement import Experiment
    e = Experiment()
    session = {'port_monitor': 1,
               'time_resolution': Q_('1ms'),
               'refresh_time': Q_('20ms'),
               'total_time': Q_('15s')}
    e.properties = session

    m = ConfigWindow(e)
    m.show()
    ap.exit(ap.exec_())
Ejemplo n.º 12
0
        self.experiment.save_scan_data(file)

    def closeEvent(self, evnt):
        print('Closing')
        super().closeEvent(evnt)


if __name__ == "__main__":
    import sys
    from PyQt5.QtWidgets import QApplication
    from PythonForTheLab.Model.experiment.IV_measurement import Experiment

    e = Experiment()
    session = {
        'port_monitor': 1,
        'time_resolution': Q_('1ms'),
        'refresh_time': Q_('100ms'),
        'total_time': Q_('15s'),
        'scan_port_out': 1,
        'scan_start': Q_('0.1V'),
        'scan_stop': Q_('0.7V'),
        'scan_step': Q_('0.1V'),
        'scan_port_in': 2,
        'scan_delay': Q_('10ms'),
    }
    e.properties = session

    app = QApplication(sys.argv)
    s = ScanWindow(e)
    s.show()
    app.exit(app.exec_())
Ejemplo n.º 13
0
        """ Reads the analog value from a specified port.

        :param int port: Port number from which to read the value
        """
        query_string = 'IN:CH{}'.format(port)
        value_bits = int(self.driver.query(query_string))
        value_volts = value_bits / 1024 * Q_('3.3V')
        return value_volts

    def set_analog_value(self, port, value):
        """ Sets the analog value of a given port.

        :param int port: Port on which to generate the output.
        :param Quantity value: Voltage to output.
        """
        value = int(value.m_as('V') / 3.3 * 4095)
        print("Setting value: {}".format(value))
        query_string = 'OUT:CH{}:{}'.format(port, value)
        self.driver.write(query_string)
        from time import sleep
        sleep(0.1)


if __name__ == "__main__":
    from time import sleep
    d = AnalogDaq('/dev/ttyACM0')
    sleep(0.5)
    print(d.idn())
    value = Q_('3.0V')
    d.set_analog_value(0, value)
    print('Got value: {:2.2f}'.format(d.get_analog_value(0)))
Ejemplo n.º 14
0
 def test_analog_output(self):
     try:
         self.dummy_model.set_analog_value(0, Q_('10V'))
     except:
         self.fail('Faild to set the analog output')