Source code for device.oscope_ds1074z
import time
import numpy as np
from .oscope_mso5000 import Oscope_MSO5000
from . import base
[docs]
class Oscope_DS1074Z(Oscope_MSO5000):
"""Oscilloscope (interferometry experiment).
Model name: RIGOL DS1074Z
Communication:
- LAN, using VISA protocol and SCPI commands
"""
# ==== Inherited abstract methods ====
def _defaultstate(self):
"""Init device to a well defined state. (Auto called after connect.)"""
# Setup private variables
self._channels = [1, 2, 3, 4]
self._activechannel = 1
# Reset all settings and restrict non-remote access
# self.raw_scpi(":system:reset")
# self.raw_scpi(":system:locked on")
# Set correct probe ratio (real meassured volts : volts at probe cable)
for ch in self._channels:
self.raw_scpi(":channel{}:probe 1".format(ch))
# Time axis mode
self.raw_scpi(":timebase:mode main")
# Fast Fourier transform
# for ch in self._channels:
ch = self.active_ch
prefix = ":math"
self.raw_scpi(prefix + ":operator fft")
self.raw_scpi(prefix + ":fft:unit db")
if self.raw_scpi(prefix + ":source1?").strip() != "CHAN{}".format(ch):
self.raw_scpi(prefix + ":source1 channel{}".format(ch)) # This does not do what it should
if int(self.raw_scpi(prefix + ":display?")) == 0:
self.raw_scpi(prefix + ":display on")
self.raw_scpi("*idn?") # Arbitrary query to wait for operations to finish
def _clear_defaultstate(self):
"""Clean-up device settings (i.e. keys lock). (Auto called before disconnect.)"""
# self.raw_scpi(":system:locked off")
pass
# ==== Private methods and commands ====
@base.base_command
def _read_waveform(self, source):
return super()._read_waveform(source if not source.startswith("math") else "math")
# ==== Commands ====
[docs]
@base.base_command
def set_freqaxis(self, low, high):
"""FFT: Horizontal frequency axis of active channel.
:param float low: lowest frequency [Hz]
:param float high: highest frequency [Hz]
"""
prefix = ":math:fft"
low = float(low)
high = float(high)
scale = abs(high - low) / 12
center = (low + high) / 2
self.raw_scpi(prefix + ":hscale {:.6e}".format(scale))
self.raw_scpi(prefix + ":hcenter {:.6e}".format(center))
[docs]
@base.base_command
def freqaxis(self, channel):
"""FFT: Return tuple (low, high), frequency range of active channel [Hz].
"""
prefix = ":math:fft"
scale = float(self.raw_scpi(prefix + ":hscale?"))
center = float(self.raw_scpi(prefix + ":hcenter?"))
return center - 6 * scale, center + 6 * scale
[docs]
@base.base_command
def set_amplitudeaxis(self, scale=None, offset=None):
"""FFT: Amplitude scale and offset of active channel. Set one or both.
:param float scale: amplitude per screen square [dBV]
:param float offset: amplitude offset from screen center [dBV]
"""
prefix = ":math"
if scale is not None:
scale = float(scale)
self.raw_scpi(prefix + ":scale {:.6e}".format(scale))
if offset is not None:
offset = float(offset)
self.raw_scpi(prefix + ":offset {:.6e}".format(offset))
[docs]
@base.base_command
def amplitudeaxis(self):
"""FFT: Return tuple (scale, offset) of active channel amplitude axis [dBV].
"""
prefix = ":math"
scale = float(self.raw_scpi(prefix + ":scale?"))
offset = float(self.raw_scpi(prefix + ":offset?"))
return scale, offset
[docs]
@base.base_command
def set_fftwindow(self, window):
"""FFT: Set window function for active channel.
:param str window: One of 'RECT', 'BLAC', 'HANN', 'HAMM', 'FLAT', 'TRI'.
"""
W = ["RECT", "BLAC", "HANN", "HAMM", "FLAT", "TRI"]
if window not in W:
raise base.CommandError("Use one of {}".format(W))
self.raw_scpi(":math:fft:window {}".format(window))
[docs]
@base.base_command
def fftwindow(self):
"""FFT: Return window function that is used for active channel.
"""
return self.raw_scpi(":math:fft:window?")
[docs]
@base.base_command
def toggle_sound(self): # TODO Probably remove
# Doing the hard work
result = int(self.raw_scpi(":system:beeper?"))
result = 1 if result == 0 else 0
self.raw_scpi(":system:beeper {:d}".format(result))
return result