1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
|
#
# This file is part of the PyMeasure package.
#
# Copyright (c) 2013-2024 PyMeasure Developers
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
import logging
from time import sleep
from warnings import warn
from pymeasure.instruments import Instrument, SCPIUnknownMixin
from pymeasure.instruments.validators import (
strict_discrete_set,
strict_range,
truncated_range,
)
log = logging.getLogger(__name__)
log.addHandler(logging.NullHandler())
# Defined outside of the class, since it is used by `Instrument.control` without access to `self`.
MIN_GATE_TIME = 2e-8 # Programmer's guide 8-92
MAX_GATE_TIME = 1000 # Programmer's guide 8-92
MIN_BUFFER_SIZE = 4 # Programmer's guide 8-39
MAX_BUFFER_SIZE = 10000 # Programmer's guide 8-39
class CNT91(SCPIUnknownMixin, Instrument):
"""Represents a Pendulum CNT-91 frequency counter."""
CHANNELS = {"A": 1, "B": 2, "C": 3, "E": 4, "INTREF": 6}
def __init__(self, adapter, name="Pendulum CNT-91", **kwargs):
# allow long-term measurements, add 30 s for data transfer
kwargs.setdefault("timeout", 24 * 60 * 60 * 1000 + 30)
kwargs.setdefault("read_termination", "\n")
super().__init__(
adapter,
name,
asrl={"baud_rate": 256000},
**kwargs,
)
@property
def batch_size(self):
"""Get maximum number of buffer entries that can be transmitted at once."""
if not hasattr(self, "_batch_size"):
self._batch_size = int(self.ask("FORM:SMAX?"))
return self._batch_size
external_start_arming_source = Instrument.control(
"ARM:SOUR?",
"ARM:SOUR %s",
"""Control external arming source ('A', 'B', 'E' (rear) or 'IMM' for immediately arming).""", # noqa: E501
validator=strict_discrete_set,
values={"A": "EXT1", "B": "EXT2", "E": "EXT4", "IMM": "IMM"},
map_values=True,
)
external_arming_start_slope = Instrument.control(
"ARM:SLOP?",
"ARM:SLOP %s",
"""Control slope for the start arming condition (str 'POS' or 'NEG').""",
validator=strict_discrete_set,
values=["POS", "NEG"],
)
continuous = Instrument.control(
"INIT:CONT?",
"INIT:CONT %s",
"""Control whether to perform continuous measurements.""",
strict_discrete_set,
values={True: 1.0, False: 0.0},
map_values=True,
)
@property
def measurement_time(self):
"""
Control gate time of one measurement in s (float strictly from 2e-8 to 1000).
.. deprecated:: 0.14
Use `gate_time` instead.
"""
warn("`measurement_time` is deprecated, use `gate_time` instead.", FutureWarning)
return self.gate_time
@measurement_time.setter
def measurement_time(self, value):
warn("`measurement_time` is deprecated, use `gate_time` instead.", FutureWarning)
self.gate_time = value
gate_time = Instrument.control(
":ACQ:APER?",
":ACQ:APER %s",
"""Control gate time of one measurement in s (float strictly from 2e-8 to 1000).""",
validator=strict_range,
values=[MIN_GATE_TIME, MAX_GATE_TIME], # Programmer's guide 8-92
)
format = Instrument.control(
"FORM?",
"FORM %s",
"Control response format ('ASCII' or 'REAL').",
validator=strict_discrete_set,
values={"ASCII": "ASC", "REAL": "REAL"},
map_values=True,
)
interpolator_autocalibrated = Instrument.control(
":CAL:INT:AUTO?",
"CAL:INT:AUTO %s",
"""Control if interpolators should be calibrated automatically (bool).""",
strict_discrete_set,
values={True: 1.0, False: 0.0},
map_values=True,
)
def read_buffer(self, n=MAX_BUFFER_SIZE):
"""
Read out `n` samples from the buffer.
:param n: Number of samples that should be read from the buffer. The maximum number of
10000 samples is read out by default.
:return: Frequency values from the buffer.
"""
n = truncated_range(n, [MIN_BUFFER_SIZE, MAX_BUFFER_SIZE]) # Programmer's guide 8-39
while not self.complete:
# Wait until the buffer is filled.
sleep(0.01)
return self.values(f":FETC:ARR? {'MAX' if n == MAX_BUFFER_SIZE else n}")
def configure_frequency_array_measurement(self, n_samples, channel, back_to_back=True):
"""
Configure the counter for an array of measurements.
:param n_samples: The number of samples
:param channel: Measurement channel (A, B, C, E, INTREF)
:param back_to_back: If True, the buffer measurement is performed back-to-back.
"""
n_samples = truncated_range(n_samples, [MIN_BUFFER_SIZE, MAX_BUFFER_SIZE])
channel = strict_discrete_set(channel, self.CHANNELS)
channel = self.CHANNELS[channel]
self.write(f":CONF:ARR:FREQ{':BTB' if back_to_back else ''} {n_samples},(@{channel})")
def buffer_frequency_time_series(
self,
channel,
n_samples,
sample_rate=None, # deprecated, only kept for backwards compatibility
gate_time=None,
trigger_source=None,
back_to_back=True,
):
"""
Record a time series to the buffer and read it out after completion.
:param channel: Channel that should be used
:param n_samples: The number of samples
:param gate_time: Gate time in s
:param trigger_source: Optionally specify a trigger source to start the measurement
:param back_to_back: If True, the buffer measurement is performed back-to-back.
:param sample_rate: Sample rate in Hz
.. deprecated:: 0.14
Use parameter `gate_time` instead.
"""
if (gate_time is None) and (sample_rate is None):
raise ValueError("`gate_time` must be specified.")
if sample_rate is not None:
warn("`sample_rate` is deprecated, use `gate_time` instead.", FutureWarning)
if gate_time is not None:
raise ValueError("Only one of `gate_time` and `sample_rate` can be specified.")
gate_time = 1 / sample_rate
self.clear()
self.format = "ASCII"
self.configure_frequency_array_measurement(n_samples, channel, back_to_back=back_to_back)
self.continuous = False
self.gate_time = gate_time
if trigger_source:
self.external_start_arming_source = trigger_source
# start the measurement (or wait for trigger)
self.write(":INIT")
|