示例#1
0
    def initialise(self):
        self.pulser = Pulser()
        self.scope = Oscilloscope(v_channel = 1, i_channel = 2)
        self.lockin = Lockin()

        self.stabilisation_time = lockin.get_timeconstant()*3

        self.pulser.voltage_off()
        sleep(2)
        self.scope.set_offsets()
        self.pulser.voltage_on()
示例#2
0
def trace_random():
    """Test the Oscilloscope with random data.
    """
    channel = Channel()
    par = Par(Random(channel), Oscilloscope(channel))
    par.start()
    return
示例#3
0
def trace_cos():
    """Plot a cosine wave on the oscilloscope.
    """
    channels = Channel(), Channel()
    par = Par(GenerateFloats(channels[0]), Cos(channels[0], channels[1]),
              Oscilloscope(channels[1]))
    par.start()
    return
示例#4
0
def trace_mux():
    """Plot sine and cosine waves on the oscilloscope.
    """
    channels = [Channel() for i in range(6)]
    par = Par(GenerateFloats(channels[0]),
              Delta2(channels[0], channels[1], channels[2]),
              Cos(channels[1], channels[3]), Sin(channels[2], channels[4]),
              Mux2(channels[3], channels[4], channels[5]),
              Oscilloscope(channels[5]))
    par.start()
    return
示例#5
0
def chart_accel():
    """Requires a Toradex Oak G to be attached to a USB port."""
    import dsp
    from toradex_csp import Accelerometer
    channels = [Channel() for i in range(7)]
    par = Par(Accelerometer(channels[0]),
              dsp.Unzip(channels[0], (channels[0:3])), Blackhole(channels[1]),
              Blackhole(channels[2]), dsp.Difference(channels[1], channels[2]),
              dsp.Square(channels[2], channels[3]), Oscilloscope(channels[3]))
    par.start()
    return
    def __init__(self, name):
        Node.__init__(self, name, terminals={'In1': {'io':'in'}, 'In2': {'io':'in'}})

        #Create an oscilloscope
        self.osc_widget = Oscilloscope()

        # Create and and a new dock on top of tools and add oscilloscope to it
        self.dock = Dock(name)
        global_data.area.addDock(self.dock, 'above', global_data.tool_dock)
        self.dock.addWidget(self.osc_widget)

        # Create plots for both inputs
        self.plot_item_1 = self.osc_widget.pwidget.plot()
        self.plot_item_2 = self.osc_widget.pwidget2.plot()
示例#7
0
class LIV():
    def __init__(self):
        self.voltage_start = 1
        self.voltage_max = 8
        self.current_max = 0.25
        self.voltage_step = 0.1

    def initialise(self):
        self.pulser = Pulser()
        self.scope = Oscilloscope(v_channel = 1, i_channel = 2)
        self.lockin = Lockin()

        self.stabilisation_time = lockin.get_timeconstant()*3

        self.pulser.voltage_off()
        sleep(2)
        self.scope.set_offsets()
        self.pulser.voltage_on()

    def measure(self):
        self.scope.reset_offsets()
        self.pulser.voltage_off()
        sleep(2)
        self.scope.set_offsets()
        self.pulser.voltage_on()

        pulser_v_limit = self.pulser.max_voltage(self.pulser.read_DC())

        with open(fname, 'w') as f:
            for v in np. np.arange(self.voltage_start, pulser_v_limit, self.voltage_step):
                sleep(self.stabilisation_time)
                volt = self.scope.get_value(scope.v_channel)
                curr = self.scope.get_value(scope.i_channel)
                sig = self.lockin.read()
                f.write('{0}\t{1}\t{2}'.format(curr, volt, sig))
                if (volt >= self.voltage_max) or (curr >= self.current_max):
                    break

        self.pulser.voltage_off()
示例#8
0
def _scope_init(addr: str) -> Oscilloscope:
    scope = Oscilloscope(addr)
    scope.write("XY_DISPLAY ON; ACQUIRE_WAY SAMPLING")
    time.sleep(0.2)
    scope.write("TIME_DIV 10US")
    scope.write("GRID_DISPLAY OFF")
    time.sleep(0.2)
    for channel in range(1, 3):
        scope.write(f"BANDWIDTH_LIMIT C{channel}, ON")
        scope.write(f"C{channel}:VOLT_DIV {SCOPE_LEVEL_FULL}")
    scope.write("MENU OFF")
    return scope
from __future__ import division
from __future__ import print_function
from oscilloscope import Oscilloscope

import signal
import sys
import numpy as np
import scipy
import scipy.stats
import pylab as pl

SAMPLING_RATE = 5000        # Hz
MIN_FREQ = 10               # Hz
N_BINS = int(round(SAMPLING_RATE/MIN_FREQ))

oscilloscope = Oscilloscope(sampling_rate=SAMPLING_RATE, port='/dev/ttyUSB0')
for i in range(N_BINS): oscilloscope.read() # Throw away some data

print('Estimating frequency...')
estimates = []
for i_estimate in range(10):
    data = [oscilloscope.read()[0] for i in range(N_BINS)]
    autocorr = np.correlate(data, data, mode='full')[len(data)-1:]
    max_pos = 0
    while autocorr[max_pos+1] < autocorr[max_pos]: max_pos += 1
    while autocorr[max_pos+1] > autocorr[max_pos]: max_pos += 1
    estimates.append(SAMPLING_RATE/max_pos)

freq = scipy.stats.mode(estimates)[0][0]
samples_per_cycle = int(round(SAMPLING_RATE/freq))
samples_per_second = int(round(SAMPLING_RATE/freq))
示例#10
0
def main():
    file_write = FileWrite()
    device_detection = Device_detection()
    device_detection.async_connect()
    I = device_detection.device

    # instrument cluster initialization
    oscilloscope = Oscilloscope(I, file_write)
    logic_analyser = LogicAnalyser(I, file_write)
    power_source = Power_source(I, file_write)
    multimeter = Multimeter(I, file_write)
    wave_generator = Wave_generator(I, file_write)
    robotic_arm = RoboticArm(I, file_write)
    sensors = Sensors(I, file_write)

    while (True):
        in_stream_data = input()
        parsed_stream_data = json.loads(in_stream_data)
        command = parsed_stream_data['command']

        # ---------------------------- Oscilloscope block ------------------------------
        if command == 'START_OSC':
            oscilloscope.start_read()

        if command == "STOP_OSC":
            oscilloscope.stop_read()

        if command == "SET_CONFIG_OSC":
            old_read_state = oscilloscope.is_reading_voltage or oscilloscope.is_reading_fft or oscilloscope.is_reading_xy_plot
            if old_read_state:
                oscilloscope.stop_read()

            time_base = parsed_stream_data['timeBase']
            number_of_samples = parsed_stream_data['numberOfSamples']
            ch1 = parsed_stream_data['ch1']
            ch2 = parsed_stream_data['ch2']
            ch3 = parsed_stream_data['ch3']
            mic = parsed_stream_data['mic']
            # ch1_map = parsed_stream_data['ch1Map']
            # ch2_map = parsed_stream_data['ch2Map']
            # ch3_map = parsed_stream_data['ch3Map']
            is_trigger_active = parsed_stream_data['isTriggerActive']
            trigger_voltage = parsed_stream_data['triggerVoltage']
            trigger_channel = parsed_stream_data['triggerChannel']
            is_fourier_transform_active = parsed_stream_data[
                'isFourierTransformActive']
            fit_type = parsed_stream_data['fitType']
            fit_channel1 = parsed_stream_data['fitChannel1']
            fit_channel2 = parsed_stream_data['fitChannel2']
            is_xy_plot_active = parsed_stream_data['isXYPlotActive']
            plot_channel1 = parsed_stream_data['plotChannel1']
            plot_channel2 = parsed_stream_data['plotChannel2']
            oscilloscope.set_config(
                time_base, number_of_samples, ch1, ch2, ch3, mic,
                is_trigger_active, trigger_channel, trigger_voltage,
                is_fourier_transform_active, fit_type, fit_channel1,
                fit_channel2, is_xy_plot_active, plot_channel1, plot_channel2)

            if old_read_state:
                oscilloscope.start_read()

        if command == 'GET_CONFIG_OSC':
            oscilloscope.get_config()

        # ---------------------------- LA block ------------------------------
        if command == 'START_LA':
            logic_analyser.start_read()

        if command == "STOP_LA":
            logic_analyser.stop_read()

        if command == "SET_CONFIG_LA":
            number_of_channels = parsed_stream_data['numberOfChannels']
            trigger1_type = parsed_stream_data['trigger1Type']
            trigger2_type = parsed_stream_data['trigger2Type']
            trigger3_type = parsed_stream_data['trigger3Type']
            trigger4_type = parsed_stream_data['trigger4Type']
            capture_time = parsed_stream_data['captureTime']
            logic_analyser.set_config(number_of_channels, trigger1_type,
                                      trigger2_type, trigger3_type,
                                      trigger4_type, capture_time)

        if command == 'GET_CONFIG_LA':
            logic_analyser.get_config()

        # --------------------------- Multimeter block ---------------------------------
        if command == 'START_MUL_MET':
            multimeter.start_read()

        if command == 'STOP_MUL_MET':
            multimeter.stop_read()

        if command == 'SET_CONFIG_MUL_MET':
            old_read_state = multimeter.is_reading
            if multimeter.is_reading:
                multimeter.stop_read()

            active_category = parsed_stream_data['activeCategory']
            active_subtype = parsed_stream_data['activeSubType']
            parameter = None
            if active_category == 'PULSE':
                parameter = parsed_stream_data['parameter']
            multimeter.set_config(active_category, active_subtype, parameter)

            if old_read_state:
                multimeter.start_read()

        if command == 'GET_CONFIG_MUL_MET':
            multimeter.get_config()

        # -------------------------- Power Source block ---------------------------------
        if command == 'SET_CONFIG_PWR_SRC':
            pcs_value = parsed_stream_data['pcs']
            pv1_value = parsed_stream_data['pv1']
            pv2_value = parsed_stream_data['pv2']
            pv3_value = parsed_stream_data['pv3']
            power_source.set_config(pcs_value, pv1_value, pv2_value, pv3_value)

        if command == 'GET_CONFIG_PWR_SRC':
            power_source.get_config()

        if command == 'GET_CONFIG_PWR_SRC_FILE':
            data_path = parsed_stream_data['dataPath']
            power_source.get_config_from_file(data_path)

        if command == 'SAVE_CONFIG_PWR_SRC':
            data_path = parsed_stream_data['dataPath']
            power_source.save_config(data_path)

        # -------------------------- Wave Generator block ---------------------------------
        if command == 'SET_CONFIG_WAV_GEN':
            wave = parsed_stream_data['wave']
            digital = parsed_stream_data['digital']
            s1_frequency = parsed_stream_data['s1Frequency']
            s2_frequency = parsed_stream_data['s2Frequency']
            s2_phase = parsed_stream_data['s2Phase']
            wave_form_s1 = parsed_stream_data['waveFormS1']
            wave_form_s2 = parsed_stream_data['waveFormS2']
            pwm_frequency = parsed_stream_data['pwmFrequency']
            sqr1_duty_cycle = parsed_stream_data['sqr1DutyCycle']
            sqr2_duty_cycle = parsed_stream_data['sqr2DutyCycle']
            sqr2_phase = parsed_stream_data['sqr2Phase']
            sqr3_duty_cycle = parsed_stream_data['sqr3DutyCycle']
            sqr3_phase = parsed_stream_data['sqr3Phase']
            sqr4_duty_cycle = parsed_stream_data['sqr4DutyCycle']
            sqr4_phase = parsed_stream_data['sqr4Phase']
            wave_generator.set_config(wave, digital, s1_frequency,
                                      s2_frequency, s2_phase, wave_form_s1,
                                      wave_form_s2, pwm_frequency,
                                      sqr1_duty_cycle, sqr2_duty_cycle,
                                      sqr2_phase, sqr3_duty_cycle, sqr3_phase,
                                      sqr4_duty_cycle, sqr4_phase)

        if command == 'GET_CONFIG_WAV_GEN':
            wave_generator.get_config()

        if command == 'GET_CONFIG_WAV_GEN_FILE':
            data_path = parsed_stream_data['dataPath']
            wave_generator.get_config_from_file(data_path)

        if command == 'SAVE_CONFIG_WAV_GEN':
            data_path = parsed_stream_data['dataPath']
            wave_generator.save_config(data_path)

        # ------------------------------- Robtic Arm block -------------------------------
        if command == 'SET_ROBO_ARM':
            angle1 = parsed_stream_data['angle1']
            angle2 = parsed_stream_data['angle2']
            angle3 = parsed_stream_data['angle3']
            angle4 = parsed_stream_data['angle4']
            robotic_arm.setServo(angle1, angle2, angle3, angle4)

        # ------------------------------- Sensors block ----------------------------------
        if command == 'SENSORS_SCAN':
            sensors.scan()

        # -------------------------------- Write block -----------------------------------

        if command == 'START_WRITE':
            data_path = parsed_stream_data['dataPath']
            device_type = parsed_stream_data['deviceType']
            file_write.start_recording(data_path, device_type)

        if command == 'STOP_WRITE':
            file_write.stop_recording()

        # -------------------------- Script termination block ----------------------------
        if command == 'KILL':
            exit()
示例#11
0
def _init_oscilloscope(addr):
    scope = Oscilloscope(addr)
    scope.write("XY_DISPLAY ON; ACQUIRE_WAY SAMPLING")
    time.sleep(0.2)
    scope.write("TIME_DIV 50US")
    scope.write("GRID_DISPLAY OFF")
    time.sleep(0.2)
    for channel in range(1, 3):
        scope.write(f"BANDWIDTH_LIMIT C{channel}, ON")
        scope.write(f"C{channel}:VOLT_DIV 0.05")
    scope.write("MENU OFF")
示例#12
0
# -*- coding: utf-8 -*-
"""
Editor de Spyder

Este es un archivo temporal
"""

import numpy as np
import matplotlib.pyplot as plt
from oscilloscope import Oscilloscope

osci = Oscilloscope(resource='USB0::0x0699::0x0363::C108011::INSTR',
                    backend='')


def pantallas(n=1500, umbral=-0.08):

    osci.setup_curve('CH2')
    osci.get_waveform_preamble()

    fotones = np.zeros(n, dtype=int)
    x = np.zeros(2500, dtype=float)
    y = np.zeros(2500, dtype=float)

    for i in range(n):
        x, y = osci.get_curve(auto_wfmpre=False)
        y = y * (y < umbral)
        dy = np.diff(y)
        yp = y[1:] * (dy < 0)
        fotones[i] = len(dy[dy < 0])
示例#13
0
 def _on_show(self, evt):
     self._osc = Oscilloscope(_PLOT_N_DIV_X, _PLOT_N_DIV_Y, self.scope)
     evt.Skip()
示例#14
0
class MainFrame(gui.MainFrameBase):
    def __init__(self):
        gui.MainFrameBase.__init__(self, None)
        self._cur_signal = 0
        self._signals = []
        self._osc = None
        self._t = 0.
        self._plot_frame_tmr = wx.Timer(self)
        self._on_change_time_div()
        self._on_change_setup_vert_div()
        self._on_toogle_run()
        self._bind_events()
        # Frame auto-size
        self.SetInitialSize()
        self._connect()

    def _connect(self):
        self._client = client.Client('localhost', 2000, self._rcv_handler)

    def _rcv_handler(self, msg):
        entries = msg.decode().split(sep='\n')
        for entry in entries:
            if entry == '':
                break

            fields = entry.split()
            if fields[0] == '#':
                self._signals = []
                for fname in fields[1:]:
                    self.signal_list.Append(fname)
                    #TODO change header
                    self._signals.append(Signal())
                    self._signals[-1].disable()
            else:
                dt = float(fields[0])
                self._t += dt
                if self._t >= self._sample_time:
                    step = self._t * self._scale_per_sec
                    self._t = 0.
                    for i in range(len(fields) - 1):
                        if self._signals[i].isenable:
                            self._signals[i].append([(step,
                                float(fields[i+1]) * self._vert_scale)])
                            break

    def _bind_events(self):
        self.Bind(wx.EVT_SHOW, self._on_show)
        self.Bind(wx.EVT_CLOSE, self._on_close)
        self.Bind(wx.EVT_TIMER, self._plot_frame, self._plot_frame_tmr)
        self.time_div_val.Bind(wx.EVT_CHOICE, self._on_change_time_div)
        self.time_div_unit.Bind(wx.EVT_CHOICE, self._on_change_time_div)
        self.setup_vert_div_val.Bind(wx.EVT_CHOICE,
                                     self._on_change_setup_vert_div)
        self.setup_vert_div_unit.Bind(wx.EVT_CHOICE,
                                      self._on_change_setup_vert_div)
        self.signal_list.Bind(wx.EVT_CHOICE, self._on_change_signal_list)
        self.run_btn.Bind(wx.EVT_TOGGLEBUTTON, self._on_toogle_run)

    def _on_show(self, evt):
        self._osc = Oscilloscope(_PLOT_N_DIV_X, _PLOT_N_DIV_Y, self.scope)
        evt.Skip()

    def _on_close(self, evt):
        self._plot_frame_tmr.Stop()
        self._client.close()
        self._osc.close()
        evt.Skip()

    def _on_change_time_div(self, *_):
        val = int(self._get_choice(self.time_div_val))
        mul = self._unit_to_mul(self._get_choice(self.time_div_unit))
        self._sec_per_div = val * mul

        self._sample_time = self._sec_per_div / _PLOT_SAMPLES_PER_DIV
        self._scale_per_sec = 1. / (_PLOT_N_DIV_Y * self._sec_per_div)
        self._reset_frame()

    def _on_change_setup_vert_div(self, *_):
        val = int(self._get_choice(self.setup_vert_div_val))
        mul = self._vert_unit_to_mul(self._get_choice(self.setup_vert_div_unit))
        self._val_per_div = val * mul

        self._vert_scale = 1. / (self._val_per_div * _PLOT_N_DIV_Y)
        self._reset_frame()

    def _on_change_signal_list(self, *_):
        self._cur_signal = self.signal_list.GetSelection()
        for sig in self._signals:
            sig.disable()
        self._signals[self._cur_signal].enable()
        self._osc.reset(self._signals)

    def _on_toogle_run(self, *_):
        if self.run_btn.GetValue():
            self._plot_frame_tmr.Start(_PLOT_PERIOD * 1000) # to ms
            self.run_btn.SetBackgroundColour(wx.Colour(0, 169, 0))
            self.run_btn.SetLabel("Run")
        else:
            self._plot_frame_tmr.Stop()
            self.run_btn.SetLabel("Stop")
            self.run_btn.SetBackgroundColour(wx.Colour(255, 0, 0))

    def _reset_frame(self):
        if self._osc != None:
            self._osc.reset(self._signals)

    def _plot_frame(self, *_):
        if self._osc != None:
            self._osc.plot(self._signals)

    def _get_choice(self, choice):
        return choice.GetString(choice.GetSelection())

    def _unit_to_mul(self, unit):
        if unit == "ns":
            return 1.E-9
        elif unit == "us":
            return 1.E-6
        elif unit == "ms":
            return 1.E-3
        elif unit == "s":
            return 1.

    def _vert_unit_to_mul(self, unit):
        if unit == "u":
            return 1.E-6
        elif unit == "m":
            return 1.E-3
        elif unit == "k":
            return 1.E3
        elif unit == "M":
            return 1.E6
        elif unit == "-":
            return 1.