Exemple #1
0
def run():
    quit_ = False

    def do_quit(*args, **kwargs):
        nonlocal quit_
        quit_ = 'quit from SIGINT'

    def on_stop(event, message):
        nonlocal quit_
        quit_ = 'quit from stop duration'

    if len(sys.argv) != 2:
        print("usage: python3 capture_jls.py [filename]")
        return 1
    filename = sys.argv[1]
    signal.signal(signal.SIGINT, do_quit)
    device = scan_require_one(config='auto')
    with device:
        recorder = DataRecorder(filename, calibration=device.calibration)
        try:
            device.stream_process_register(recorder)
            data = device.start(stop_fn=on_stop)
            print('Capturing data: type CTRL-C to stop')
            while not quit_:
                time.sleep(0.01)
        finally:
            recorder.close()
    return 0
Exemple #2
0
def run():
    _quit = False

    def on_stop(*args, **kwargs):
        nonlocal _quit
        _quit = True

    args = get_parser().parse_args()
    device = scan_require_one(config='auto')
    device.parameter_set('buffer_duration', 2)  # could be smaller
    stream_process = StreamProcess(args.duration, device.sampling_frequency)

    signal.signal(signal.SIGINT, on_stop)

    # Perform the data capture
    with device:
        device.stream_process_register(stream_process)
        device.start(stop_fn=on_stop, duration=args.duration)
        while not _quit:
            time.sleep(0.1)
        device.stop()  # for CTRL-C handling (safe for duplicate calls)
    data = stream_process.data
    print_stats(data, device.sampling_frequency)

    if args.plot:
        plot_iv(data, device.sampling_frequency)

    return 0
def run():
    _quit = False
    args = get_parser().parse_args()

    def on_stop(*args, **kwargs):
        nonlocal _quit
        _quit = True

    def on_statistics(statistics):
        nonlocal _quit
        v_data = statistics['signals']['voltage']['µ']
        v = v_data['value']
        u = v_data['units']
        now = str(datetime.datetime.now())
        print(f'{now} : {v:.3f} {u}')
        if v < args.threshold:
            print(f'{now} : input voltage below threshold')
            _quit = True

    device = scan_require_one(config='auto')
    device.parameter_set('buffer_duration', 2)  # could be smaller
    signal.signal(signal.SIGINT, on_stop)

    # Perform the data capture
    with device:
        device.statistics_callback = on_statistics
        device.start(stop_fn=on_stop)
        while not _quit:
            time.sleep(0.1)
        device.stop()  # for CTRL-C handling (safe for duplicate calls)
    return 0
def run():
    _quit = False

    def on_stop(*args, **kwargs):
        nonlocal _quit
        _quit = True

    args = get_parser().parse_args()
    device = scan_require_one(config='auto')
    signal.signal(signal.SIGINT, on_stop)
    window_detect = WindowDetect(args.out)
    gpo = 0
    gpo_count = 0

    # Perform the data capture
    with device:
        device.parameter_set('current_lsb', 'gpi0')
        device.parameter_set('io_voltage', f'{args.io_voltage:.1f}V')
        device.parameter_set('gpo0', gpo)
        device.parameter_set('gpo1', '1')
        device.start(stop_fn=on_stop)
        print('Detecting triggers.  Press CTRL-C to exit.')
        print(CSV_HEADER)
        while not _quit:
            time.sleep(0.1)
            gpo_count += 1
            if gpo_count >= 10:
                gpo = 0 if gpo else 1
                device.parameter_set('gpo0', gpo)
                gpo_count = 0
            window_detect(device.stream_buffer)

        device.stop()  # for CTRL-C handling (safe for duplicate calls)
        window_detect.close()
    return 0
Exemple #5
0
def run():
    device = scan_require_one(config='auto')
    with device:
        data = device.read(contiguous_duration=0.001)
    current, voltage = data[-1, :]
    print(f'{current} A, {voltage} V')
    return 0
def run():
    device = scan_require_one(config='auto')
    with device:
        # turn filter off just to demonstrate
        device.parameter_set('current_ranging_type', 'off')

        # configure an aggressive filter using single field (recommended way).
        device.parameter_set('current_ranging', 'mean_1_3_1')
        print('read 1: ' + device.parameter_get('current_ranging'))
        device.read(contiguous_duration=0.5)

        # configure a very conservative filter using individual fields
        device.parameter_set('current_ranging_type', 'mean')
        device.parameter_set('current_ranging_samples_pre', 4)
        device.parameter_set('current_ranging_samples_window', 8)
        device.parameter_set('current_ranging_samples_post', 4)
        print('read 2: ' + device.parameter_get('current_ranging'))
        device.read(contiguous_duration=0.5)

        # insert a single NaN on each current range change.
        device.parameter_set('current_ranging', 'nan_0_1_0')
        print('read 3: ' + device.parameter_get('current_ranging'))
        device.read(contiguous_duration=0.5)

    return 0
def run():
    count = 0
    _quit = False

    def stop_fn(*args, **kwargs):
        nonlocal _quit
        _quit = True

    # do not use config='auto' so that we can set io_voltage first.
    with scan_require_one(name='Joulescope') as js:
        # configure target Joulescope
        js.parameter_set('io_voltage', '3.3V')
        js.parameter_set('voltage_lsb', 'gpi0')
        js.parameter_set('gpo0', '0')
        js.parameter_set('gpo1', '0')
        js.parameter_set('sensor_power', 'on')
        js.parameter_set('source', 'on')
        js.parameter_set('i_range', '18 mA')

        # start data streaming for 1 second, toggle gpo0 with ~20 ms period
        js.start(stop_fn=stop_fn, duration=1.0)
        while not _quit:
            js.parameter_set('gpo0', str(count & 1))
            count += 1
            time.sleep(0.01)

        # analyze the collected voltage_lsb data for edges
        data = js.stream_buffer.samples_get(*js.stream_buffer.sample_id_range,
                                            fields=['current', 'voltage_lsb'])
        current = data['signals']['current']['value']
        out0 = data['signals']['voltage_lsb']['value']
        edges_idx = np.nonzero(np.diff(out0))[0]
        edge_count = len(edges_idx)
        print(f'Found {edge_count} out0 edges')

        # and plot the results
        f = plt.figure()
        ax_gpi = f.add_subplot(2, 1, 1)
        ax_gpi.set_ylabel('GPI')
        ax_gpi.grid(True)

        ax_i = f.add_subplot(2, 1, 2, sharex=ax_gpi)
        ax_i.set_ylabel('Current (A)')
        ax_i.grid(True)
        ax_i.set_xlabel('Time (samples)')

        x_lead = 2
        x_lag = 11  # exclusive
        x = np.arange(-x_lead, x_lag)

        for edge_idx in range(edge_count):
            idx = edges_idx[edge_idx]
            if idx < x_lead or idx > len(out0) - x_lag:
                continue
            ax_gpi.plot(x, out0[idx - x_lead:idx + x_lag])
            ax_i.plot(x, current[idx - x_lead:idx + x_lag])

        plt.show()
        plt.close(f)
Exemple #8
0
 def _run_sensor(self, args):
     device = scan_require_one(config='off')
     device.statistics_callback_register(self._on_statistics, 'sensor')
     with device:
         device.parameter_set('i_range', 'auto')
         device.parameter_set('v_range', '15V')
         self._display_run_info(args)
         while not self._quit:
             device.status()
             time.sleep(0.1)
Exemple #9
0
 def _run_stream_buffer(self, args):
     device = scan_require_one(config='auto')
     device.parameter_set('buffer_duration', 1)
     signal.signal(signal.SIGINT, self._on_user_exit)
     with device:
         device.statistics_callback = self._on_statistics
         device.start(stop_fn=self._on_stop, duration=args.duration)
         self._display_run_info(args)
         while not self._quit:
             time.sleep(0.01)
def run():
    args = get_parser().parse_args()
    device = scan_require_one(config='ignore')
    device.parameter_set('buffer_duration', 10)
    if args.sampling_frequency is not None:
        device.parameter_set('sampling_frequency',
                             int(args.sampling_frequency))
    signal.signal(signal.SIGINT, _on_stop)
    gpo = 0
    gpo_count = 0

    # Perform the data capture
    with device:
        device.parameter_set('io_voltage', f'{args.io_voltage:.1f}V')
        device.parameter_set('gpo0', 0)
        device.parameter_set('gpo1', 1)
        if ('in0' in args.start_signal
                and args.start in IO_TRIG) or ('in0' in args.end_signal
                                               and args.end in IO_TRIG):
            device.parameter_set('current_lsb', 'gpi0')
        if ('in1' in args.start_signal
                and args.start in IO_TRIG) or ('in1' in args.end_signal
                                               and args.end in IO_TRIG):
            device.parameter_set('voltage_lsb', 'gpi1')
        capture = Capture(device, args)
        device.parameter_set('source', 'on')
        _power_off(device, args.init_power_off)
        device.parameter_set('i_range', args.current_range)
        if args.voltage_range:
            device.parameter_set('v_range', args.voltage_range)
        device.start(stop_fn=_on_stop)
        while not _quit:
            time.sleep(0.1)
            gpo_count += 1
            if gpo_count >= 10:
                gpo = 0 if gpo else 1
                if args.self_test:
                    device.parameter_set('gpo0', gpo)
                gpo_count = 0
            if capture(device.stream_buffer):
                break
        device.stop()  # for CTRL-C handling (safe for duplicate calls)
        capture.close()
        if args.power_off:
            device.parameter_set('i_range', 'off')
    return 0
Exemple #11
0
def run():
    statistics_queue = queue.Queue()  # resynchronize to main thread

    def stop_fn(*args, **kwargs):
        statistics_queue.put(None)  # None signals quit

    signal.signal(signal.SIGINT, stop_fn)  # also quit on CTRL-C

    with scan_require_one(config='auto') as device:
        device.statistics_callback = statistics_queue.put  # put data in queue
        device.start(stop_fn=stop_fn)
        print('CTRL-C to exit')
        while True:
            data = statistics_queue.get()
            if data is None:
                break
            energy = data['accumulators']['energy']
            print(three_sig_figs(energy['value'], units=energy['units']))
def run():
    statistics_queue = queue.Queue()  # resynchronize to main thread

    def stop_fn(*args, **kwargs):
        statistics_queue.put(None)  # None signals quit

    signal.signal(signal.SIGINT, stop_fn)  # also quit on CTRL-C

    with scan_require_one(config='off') as device:
        device.statistics_callback_register(statistics_queue.put, 'sensor')
        device.parameter_set('i_range', 'auto')
        device.parameter_set('v_range', '15V')
        print('CTRL-C to exit')
        while True:
            device.status()
            time.sleep(0.1)
            try:
                data = statistics_queue.get(block=False)
                if data is None:
                    break
                energy = data['accumulators']['energy']
                print(three_sig_figs(energy['value'], units=energy['units']))
            except queue.Empty:
                pass
def dut_power(power_on):
    i_range = 'auto' if power_on else 'off'
    # do not use config='auto' so that power can remain off without a glitch.
    with scan_require_one(name='Joulescope') as js:
        js.parameter_set('sensor_power', 'on')
        js.parameter_set('i_range', i_range)