From 40ac7921213814a98aee0a1990d6f67d84ceb96c Mon Sep 17 00:00:00 2001 From: Jonathan Hogg Date: Mon, 27 Mar 2017 16:18:02 +0100 Subject: [PATCH] Yet more work on triggering - still doesn't work properly for mixed/logic --- scope.py | 166 +++++++++++++++++++++++++++++------------------------ streams.py | 1 + 2 files changed, 93 insertions(+), 74 deletions(-) diff --git a/scope.py b/scope.py index 732b7ed..2afbe29 100755 --- a/scope.py +++ b/scope.py @@ -52,8 +52,8 @@ class Scope(vm.VirtualMachine): self.awg_sample_buffer_size = 1024 self.awg_minimum_clock = 33 self.awg_maximum_voltage = 3.3 - self.analog_params = (18.584, -3.5073, 298.11, 18.253, 0.40815) - self.analog_offsets = {'A': -0.011785, 'B': 0.011785} + self.analog_params = (18.52, -3.33, 296.41, 18.337, 0.40811) + self.analog_offsets = {'A': 0.0008, 'B': -0.0008} self.analog_min = -5.7 self.analog_max = 8 self.capture_clock_period = 25e-9 @@ -101,14 +101,43 @@ class Scope(vm.VirtualMachine): dh = (h*(2*ah + b) - ah*(l + 1)) / b return dl, dh - async def capture(self, channels=['A'], trigger_channel=None, trigger_level=None, trigger_type='rising', hair_trigger=False, - period=1e-3, nsamples=1000, timeout=None, low=None, high=None, raw=False, trigger_point=0.5): - channels = list(channels) - analog_channels = [channel for channel in channels if channel in {'A', 'B'}] - logic = 'L' in channels + async def capture(self, channels=['A'], trigger=None, trigger_level=None, trigger_type='rising', hair_trigger=False, + period=1e-3, nsamples=1000, timeout=None, low=None, high=None, raw=False, trigger_position=0.25): + analog_channels = [] + logic_channels = [] + for channel in channels: + if channel in {'A', 'B'}: + analog_channels.append(channel) + if trigger is None: + trigger = channel + elif channel == 'L': + logic_channels.extend(range(8)) + if trigger is None: + trigger = {0: 1} + elif channel.startswith('L'): + i = int(channel[1:]) + if i not in logic_channels: + logic_channels.append(i) + if trigger is None: + trigger = {i: 1} + else: + raise ValueError(f"Unrecognised channel: {channel}") + if self._generator_running and 4 in logic_channels: + logic_channels.remove(4) + if 'A' in analog_channels and 7 in logic_channels: + logic_channels.remove(7) + if 'B' in analog_channels and 6 in logic_channels: + logic_channels.remove(6) + analog_enable = 0 + if 'A' in channels: + analog_enable |= 1 + if 'B' in channels: + analog_enable |= 2 + logic_enable = sum(1< capture_mode.clock_max: ticks = capture_mode.clock_max nsamples = int(round(period / ticks / self.capture_clock_period / clock_scale)) - total_samples = nsamples*2 if logic and analog_channels else nsamples + total_samples = nsamples*2 if logic_channels and analog_channels else nsamples buffer_width = self.capture_buffer_size // capture_mode.sample_width if total_samples > buffer_width: raise RuntimeError("Capture buffer too small for requested capture") @@ -140,69 +169,51 @@ class Scope(vm.VirtualMachine): high = self.analog_max lo, hi = self.calculate_lo_hi(low, high) - analog_enable = 0 - if 'A' in channels: - analog_enable |= 1 - if 'B' in channels: - analog_enable |= 2 - logic_enable = 0 - for channel in range(8): - if not ((channel == 4 and self._generator_running) or (channel == 6 and 'A' in channels) or (channel == 7 and 'B' in channels)): - logic_enable |= 1< -In [6]: +In [6]: t = pandas.DataFrame(capture(['L'], low=0, high=3.3)) + +In [7]: t.plot() +Out[7]: + +In [8]: """ +import pandas + async def main(): global s parser = argparse.ArgumentParser(description="scopething") @@ -389,6 +406,7 @@ async def main(): logging.basicConfig(level=logging.DEBUG if args.debug else logging.INFO, stream=sys.stdout) s = await Scope.connect(args.device) + #await s.start_generator(2000, 'triangle') #x = np.linspace(0, 2*np.pi, s.awg_wavetable_size, endpoint=False) #y = np.round((np.sin(x)**5)*127 + 128, 0).astype('uint8') #await s.start_generator(1000, wavetable=y) diff --git a/streams.py b/streams.py index f0863dc..a7ce047 100644 --- a/streams.py +++ b/streams.py @@ -16,6 +16,7 @@ class SerialStream: for port in comports(): if port.vid == vid and port.pid == pid: return SerialStream(port.device, **kwargs) + raise RuntimeError("No matching serial device") def __init__(self, device, loop=None, **kwargs): self._device = device