Ejemplo n.º 1
0
    def _onTimer(self):
        self.last_sample_done = True
        d = dict()
        values = self.instrument.query_ascii_values('FETC:IMP?')
        self.current_bias = float(self.instrument.query('BIAS:VOLT?'))
        self.current_frequency = float(self.instrument.query('FREQ?'))
        self.current_capacitance =  values[0]
        measurement_time = time() - self.start_time

        d[self.output_channels[0]] = (dict({self.x_units[0] : self.sample_nr,
                                            self.x_units[1] : measurement_time}),
                                        dict({self.y_units[0] : self.current_capacitance,
                                            self.y_units[1] : self.current_frequency,
                                            self.y_units[2] : self.current_bias}))
        self.sample_nr += 1
#        logger.warning('_onTimer() time:  %f, primed timer with: %f, ui: %f, sn: %f',\
#            measurement_time,((self.update_interval * float(self.sample_nr)) - measurement_time) * 1000,
#            self.update_interval, float(self.sample_nr))
        if self.running:
            Timer.singleShot(max(0, ((self.update_interval * float(self.sample_nr)) - measurement_time) * 1000), self._onTimer)
        self.acquired_data.append(d)
        if self.settings_changed:
            self.settings_changed = False
            self.instrument.write('VOLT ' + str(self.osc_level))
            self.instrument.write('BIAS:VOLT ' + str(self.bias))
            self.instrument.write('FUNC:IMP ' + str(self.mode))
            self.instrument.write('FREQ ' + str(self.frequency))
Ejemplo n.º 2
0
    def _on_timer(self):
        socks = dict(self.subscriber_poller.poll(POLL_TIMEOUT))
        logger.info(socks)
        if self.subscriber in socks and socks[self.subscriber] == zmq.POLLIN:
            msg = self.subscriber.recv()
            self.connect_timeout = 0
            logger.info(msg.decode('UTF8'))
            if msg.find('NEWCOL') != -1:
                self.current_column = ({self.x_units[0]: 0},
                                       {self.y_units[0]: int(msg.strip('NEWCOL '))})
            elif msg.find('STOP') != -1:
                if self.control_gasmixer:
                    if self.active_instrument.running is True:
                        self.active_instrument.start_stop = True
            elif msg.find('START') != -1:
                if self.control_gasmixer:
                    if self.active_instrument.running is False:
                        self.active_instrument.start_stop = True
                    else:
                        self.active_instrument.start_stop = True
                        self.active_instrument.start_stop = True
                logger.info('Starting measurement')
            elif msg.find('HEARTBEAT') != -1:
                self.state = State.CONNECTED
                self.running_label = 'GasMixer ' + State.strings[self.state]

            self.timer = Timer.singleShot(0.01, self._on_timer)
            return

        self.connect_timeout += UPDATE_INTERVAL
        if self.connect_timeout > CONNECT_TIMEOUT:
            self.state = State.DISCONNECTED
            self.running_label = 'GasMixer ' + State.strings[self.state]
        self.timer = Timer.singleShot(UPDATE_INTERVAL, self._on_timer)
Ejemplo n.º 3
0
 def start(self):
     self.button_label = 'Stop'
     self.sample_nr = 1
     self.running = True
     self.instrument_init()
     self.start_time = time()
     Timer.singleShot(self.update_interval * 1000 - 200, self._onTimer)
Ejemplo n.º 4
0
    def _on_timer(self):
        self.sample_number += 1
        data = [self.sample_number, time() - self.start_time]
        if self.derivative_resistance_enabled:
            self.instrument.write('f2, msg2 = InitiatePulseTest(1)')
            response = self.instrument.query('printbuffer(1, {:d}, smua.nvbuffer1)'
                                             .format(self.derivative_resistance_voltage_points))
            self.instrument.write('smua.nvbuffer1.clear()')
            logger.info(response)
            values = [float(n) for n in response.replace(',', '').split()]
            filtered_response = savgol_filter(values, self.derivative_resistance_voltage_points, 2, 1,
                                              2*self.derivative_resistance_voltage_span /
                                              (self.derivative_resistance_voltage_points-1))
            logger.info(1/filtered_response)
            data.append(self.voltage)
            data.append(values[self.derivative_resistance_voltage_points/2])
            data.append(1/filtered_response[self.derivative_resistance_voltage_points/2])
            self.actual_current = values[self.derivative_resistance_voltage_points/2] * 1000
            self.actual_voltage = self.voltage
            self.dispatch_data(data)

        else:
            resp = self.instrument.query('print(smua.measure.iv())')
            values = [float(f) for f in resp.split()]
            data.append(values[1])
            data.append(values[0])
            data.append(values[1]/values[0])
            self.actual_voltage = values[1]
            self.actual_current = values[0] * 1000
            self.dispatch_data(data)

        if self.running:
            self.timer = Timer.singleShot(max(((self.sample_number+1) * self.sampling_interval -
                                           (time()-self.start_time))*1000, 0.01),
                                          self._on_timer)
Ejemplo n.º 5
0
    def start(self):
        self.running = True
        self.acq_start_time = time()
        self.sample_nr = 0
        self.instrument = SerialUtil.open(self.selected_device, self.visa_resource)
        if self.instrument is None:
            self.instrument = None
            self.selected_device = ''

        self.timer = Timer.singleShot(self.sampling_interval * 1000, self.add_data)
Ejemplo n.º 6
0
    def start(self):
        self.running = True
        self.acq_start_time = time()
        self.sample_nr = 0
        self.instrument = SerialUtil.open(self.selected_device, self.visa_resource)
        self.instrument_init()
        if self.instrument is None:
#            GenericPopupMessage(message ='Error opening ' + new).edit_traits()
            self.instrument = None
            self.selected_device = ''

        self.timer = Timer.singleShot(self.sampling_interval * 1000, self.add_data)
Ejemplo n.º 7
0
 def _portname_changed(self, new):
     if new is '':
         return
     if self.serialport != None:
         self.serialport.close()
     try:
         self.serialport = serial.Serial(self.portname, 115200, timeout = 0.1)
     except Exception as e:
         logger.error(e)
         return
     #self.serialport.open()
     self.serialport.flushInput()
     self.timer = Timer.singleShot(self.sample_interval, self.add_data)
Ejemplo n.º 8
0
    def __init__(self, **traits):
        if USE_ZMQ is False:
            return
        super(GasMixerPanel, self).__init__(**traits)
        self.context = zmq.Context.instance()

        self.subscriber = self.context.socket(zmq.SUB)
        self.subscriber.connect('tcp://localhost:5561')
        self.subscriber.setsockopt(zmq.SUBSCRIBE, "")
        self.subscriber_poller = zmq.Poller()
        self.subscriber_poller.register(self.subscriber, zmq.POLLIN)
        self.state = State.DISCONNECTED
        self.timer = Timer.singleShot(UPDATE_INTERVAL, self._on_timer)
Ejemplo n.º 9
0
 def add_data(self):
     if not self.running:
         return
     self.timer = Timer.singleShot(500, self.add_data)
     self.response_remainder = self.serial_response[-15:]
     self.serial_response = bytearray(self.serialport.inWaiting())
     self.serialport.readinto(self.serial_response)
     d = self._parse_data(self.response_remainder +self.serial_response)
     data_dict = dict()
     if self.running is True:
         for entry in d:
             data_dict[self.output_channels[0]] = entry[0]
             data_dict[self.output_channels[1]] = entry[1]
             self.acquired_data.append(data_dict)
Ejemplo n.º 10
0
 def start(self):
     self.running = True
     self.acq_start_time = time()
     self.sample_nr = 0
     if self.serialport is None:
         try:
             self.serialport = serial.Serial(self.portname, 57600, timeout = 0.2)
         except Exception as e:
             logger.error(e)
             self.stop()
             return
     else:
         self.serialport.open()
     self.serialport.write('a')
     self.timer = Timer.singleShot(900, self.add_data)
Ejemplo n.º 11
0
 def add_data(self):
     if not self.running:
         return
     b = bytearray(2)
     self.sample_nr += 1
     measurement_time = time() - self.acq_start_time
     self.serialport.readinto(b)
     d = dict()
     for i, enabled in enumerate(self.enabled_channels):
         d[self.output_channels[i]] = (dict({self.x_units[0]:self.sample_nr,
                                         self.x_units[1]:measurement_time}),\
                         dict({self.y_units[0]:4.9*((b[0]*256 + b[1])/1024.0)}))
     self.timer = Timer.singleShot(max(0, ((float(self.sample_nr)) - measurement_time) * 1000), self.add_data)
     self.sensor_output_voltage = 4.9*((b[0]*256 + b[1])/1024.0)
     self.acquired_data.append(d)
Ejemplo n.º 12
0
 def start(self):
     self.running = True
     self.acq_start_time = time()
     self.sample_nr = 0
     if self.serialport is None:
         try:
             self.serialport = serial.Serial(self.portname, 115200, timeout=0.045)
         except Exception as e:
             logger.error(e)
             self.stop()
             return
     else:
         self.serialport.open()
     self.serial_handler = SerialHandler(self.serialport)
     self.serial_handler.start()
     self.timer = Timer.singleShot(self.sample_interval * 1000, self.add_data)
Ejemplo n.º 13
0
 def add_data(self):
     self.sample_nr += 1
     measurement_time = time() - self.acq_start_time
     if not self.running:
         return
     (nox_ppm, lambda_linear, oxygen_millivolt) = self._poll_queue()
     self.serial_out = str(nox_ppm)
     dict_data = dict()
     for i, enabled in enumerate(self.enabled_channels):
         dict_data[
             self.output_channels[i]] = (
             dict(
                 {self.x_units[0]: self.sample_nr, self.x_units[1]: measurement_time}),
                 dict({self.y_units[0]: nox_ppm}))
     self.acquired_data.append(dict_data)
     self.timer = Timer.singleShot(max(0, (self.sample_interval * self.sample_nr -
                                           (time() - self.acq_start_time))*1000), self.add_data)
Ejemplo n.º 14
0
    def add_data(self):
        if not self.running:
            return
        self.sample_nr += 1
        try:
            data = self.instrument.query('READ?')     
        except visa.VisaIOError:
            data = self.acq_value
            pass
        self.acq_value = float(data)
        logger.info(data)
        self.measurement_time = time() - self.acq_start_time   
        d = dict()
        for i, enabled in enumerate(self.enabled_channels):

            d[self.output_channels[i]] = (dict({self.x_units[0]:self.sample_nr,
                                            self.x_units[1]:self.measurement_time}),\
                            self._fix_output_dict(self.acq_value))                           
        self.timer = Timer.singleShot(max(0,
            ((float(self.sample_nr) * self.sampling_interval) - self.measurement_time) * 1000),
            self.add_data)
        self.acquired_data.append(d)
Ejemplo n.º 15
0
    def _set_parameters_fired(self):
        enter = '\r\n'
        if self.serialport.isOpen():
            self.serialport.flushOutput()
            self.serialport.read(self.serialport.inWaiting())
            self.timer = None
            self.serialport.write('A')
            sleep(0.1)
            logger.debug(bytearray(self.serialport.read(self.serialport.inWaiting())))
            self.serialport.write(str(self.temperature) + enter)
            sleep(0.1)
            logger.debug(bytearray(self.serialport.read(self.serialport.inWaiting())))
            self.serialport.write(str(0) + enter)
            sleep(0.1)
            logger.debug(bytearray(self.serialport.read(self.serialport.inWaiting())))
            self.serialport.write(str(self.samples_per_sec) + enter)
            sleep(0.1)
            logger.debug(bytearray(self.serialport.read(self.serialport.inWaiting())))
            self.serialport.write(str(self.max_cur_drain1) + enter)
            sleep(0.1)
            logger.debug(bytearray(self.serialport.read(self.serialport.inWaiting())))
            self.serialport.write(str(self.min_cur_drain1) + enter)
            sleep(0.1)
            logger.debug(bytearray(self.serialport.read(self.serialport.inWaiting())))
            self.serialport.write(str(self.max_cur_drain2) + enter)
            sleep(0.1)
            logger.debug(bytearray(self.serialport.read(self.serialport.inWaiting())))
            self.serialport.write(str(self.min_cur_drain2) + enter)
            sleep(0.1)
            logger.debug(bytearray(self.serialport.read(self.serialport.inWaiting())))
            self.serialport.write(str(0) + enter)
            sleep(0.1)
#            sleep(0.2)            
            logger.debug(bytearray(self.serialport.read(self.serialport.inWaiting())))
            sleep(0.1)
            self.serialport.write(enter)
            logger.debug(bytearray(self.serialport.read(self.serialport.inWaiting())))
            sleep(0.1)
            self.timer = Timer.singleShot(500, self.add_data)
Ejemplo n.º 16
0
    def start(self):
        self.instrument.write('reset()')
        self.instrument.write('digio.writeprotect = 0')
        self.instrument.write('smua.measure.nplc = 5')
        self.instrument.write('smua.measure.autozero = smua.AUTOZERO_ONCE')
        self.instrument.write('smua.sense = smua.SENSE_REMOTE')
        self.instrument.write('smua.source.autorangei = smua.AUTORANGE_OFF')
        self.instrument.write('smua.source.autorangev = smua.AUTORANGE_OFF')
        self.instrument.write('smua.measure.autorangei = smua.AUTORANGE_OFF')
        self.instrument.write('smua.measure.autorangev = smua.AUTORANGE_OFF')

        if self.constant_current_mode:
            self.instrument.write('smua.source.func = smua.OUTPUT_DCAMPS')
            self.instrument.write('smua.source.limitv = {:f}'.format(self.voltage_limit))
            self.instrument.write('smua.source.leveli = {:f}'.format(self.current/1000))
            self.instrument.write('smua.source.rangei = {:f}'.format(1.2*self.current/1000))
            if self.voltage_range == 'Auto':
                self.instrument.write('smua.measure.autorangev = smua.AUTORANGE_ON')
            else:
                self.instrument.write('smua.measure.rangev = ' + self.voltage_range)
            self.instrument.write('display.smua.measure.func = smua.OUTPUT_DCVOLTS')
        else:
            self.instrument.write('smua.source.func = smua.OUTPUT_DCVOLTS')
            self.instrument.write('smua.source.limiti = {:f}'.format(self.current_limit/1000))
            self.instrument.write('smua.source.levelv = {:f}'.format(self.voltage))
            self.instrument.write('smua.source.rangev = {:f}'.format(self.voltage*1.2))

            if self.current_range == 'Auto':
                self.instrument.write('smua.measure.autorangei = smua.AUTORANGE_ON')
            else:
                self.instrument.write('smua.measure.rangei = {:f}'.format(float(self.current_range)))
            self.instrument.write('display.smua.measure.func = smua.OUTPUT_DCAMPS')
            if self.derivative_resistance_enabled:
                nplc = (0.25*(self.sampling_interval/self.derivative_resistance_voltage_points))/0.02
                logger.info('NPLC=%f', nplc)
                self.instrument.write('smua.measure.nplc = {:f}'.format(nplc))
                self.instrument.write('smua.nvbuffer1.clear()')
                self.instrument.write('smua.nvbuffer1.appendmode = 1')
                self.instrument.write('smua.source.autorangei = smua.AUTORANGE_OFF')
                self.instrument.write('smua.source.autorangev = smua.AUTORANGE_OFF')
                self.instrument.write('smua.source.rangev = {:f}'.format(self.voltage +
                                                                         self.derivative_resistance_voltage_span*1.2))
                query = 'f1, msg1 = ConfigPulseVMeasureISweepLin(smua, {:f}, {:f}, {:f}, {:f}, {:f}, 0, {:d}, ' \
                        'smua.nvbuffer1, 1)'.format(self.voltage,
                                                    self.voltage - self.derivative_resistance_voltage_span,
                                                    self.voltage + self.derivative_resistance_voltage_span,
                                                    self.current_limit/1000,
                                                    0.5*(self.sampling_interval /
                                                         self.derivative_resistance_voltage_points),
                                                    self.derivative_resistance_voltage_points)
                logger.info(query)
                self.instrument.write(query)
                response = self.instrument.query('print(f1, msg1)')
                logger.info(response)

        self.instrument.write('smua.source.output = smua.OUTPUT_ON')
        self.running = True
        self.start_time = time()
        self.sample_number = 0

        if self.running:
            self.timer = Timer.singleShot(max(((self.sample_number+1) * self.sampling_interval -
                                           (time()-self.start_time))*1000, 0.01),
                                          self._on_timer)