| 1 |
# |
| 2 |
# This file is part of the PyMeasure package. |
| 3 |
# |
| 4 |
# Copyright (c) 2013-2024 PyMeasure Developers |
| 5 |
# |
| 6 |
# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 |
# of this software and associated documentation files (the "Software"), to deal |
| 8 |
# in the Software without restriction, including without limitation the rights |
| 9 |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 |
# copies of the Software, and to permit persons to whom the Software is |
| 11 |
# furnished to do so, subject to the following conditions: |
| 12 |
# |
| 13 |
# The above copyright notice and this permission notice shall be included in |
| 14 |
# all copies or substantial portions of the Software. |
| 15 |
# |
| 16 |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 |
# THE SOFTWARE. |
| 23 |
# |
| 24 |
|
| 25 |
import logging |
| 26 |
from enum import IntEnum |
| 27 |
from pymeasure.instruments import Instrument |
| 28 |
from pymeasure.instruments.validators import strict_discrete_set, strict_range |
| 29 |
|
| 30 |
log = logging.getLogger(__name__) |
| 31 |
log.addHandler(logging.NullHandler()) |
| 32 |
|
| 33 |
|
| 34 |
class HP8657B(Instrument): |
| 35 |
""" Represents the Hewlett Packard 8657B signal generator |
| 36 |
and provides a high-level interface for interacting |
| 37 |
with the instrument. |
| 38 |
""" |
| 39 |
|
| 40 |
def __init__(self, adapter, name="Hewlett-Packard HP8657B", **kwargs): |
| 41 |
super().__init__( |
| 42 |
adapter, |
| 43 |
name, |
| 44 |
includeSCPI=False, |
| 45 |
send_end=True, |
| 46 |
**kwargs, |
| 47 |
) |
| 48 |
|
| 49 |
class Modulation(IntEnum): |
| 50 |
""" |
| 51 |
IntEnum for the different modulation sources |
| 52 |
""" |
| 53 |
EXTERNAL = 1 |
| 54 |
INT_400HZ = 2 |
| 55 |
INT_1000HZ = 3 |
| 56 |
OFF = 4 |
| 57 |
DC_FM = 5 |
| 58 |
|
| 59 |
def check_errors(self): |
| 60 |
""" |
| 61 |
Method to read the error status register |
| 62 |
as the 8657B does not support any readout of values, this will return 0 and log a warning |
| 63 |
|
| 64 |
""" |
| 65 |
log.warning("HP8657B Does not support error status readout") |
| 66 |
|
| 67 |
def clear(self): |
| 68 |
""" |
| 69 |
Reset the instrument to power-on default settings |
| 70 |
|
| 71 |
""" |
| 72 |
self.adapter.connection.clear() |
| 73 |
|
| 74 |
id = "HP,8657B,N/A,N/A" #: Manual ID entry |
| 75 |
|
| 76 |
am_depth = Instrument.setting( |
| 77 |
"AM %2.1f PC", |
| 78 |
""" |
| 79 |
Set the modulation depth for AM, |
| 80 |
usable range 0-99.9% |
| 81 |
""", |
| 82 |
validator=strict_range, |
| 83 |
values=[0, 99.9], |
| 84 |
) |
| 85 |
|
| 86 |
am_source = Instrument.setting( |
| 87 |
"AM S%i", |
| 88 |
""" |
| 89 |
Set the source for the AM function with :attr:`Modulation` enumeration. |
| 90 |
|
| 91 |
========== ======= |
| 92 |
Value Meaning |
| 93 |
========== ======= |
| 94 |
OFF no modulation active |
| 95 |
INT_400HZ internal 400 Hz modulation source |
| 96 |
INT_1000HZ internal 1000 Hz modulation source |
| 97 |
EXTERNAL External source, AC coupling |
| 98 |
========== ======= |
| 99 |
|
| 100 |
*Note:* |
| 101 |
* AM & FM can be active at the same time |
| 102 |
* only one internal source can be active at the time |
| 103 |
* use "OFF" to deactivate AM |
| 104 |
|
| 105 |
usage example: |
| 106 |
|
| 107 |
.. code-block:: python |
| 108 |
|
| 109 |
sig_gen = HP8657B("GPIB::7") |
| 110 |
... |
| 111 |
sig_gen.am_source = sig_gen.Modulation.INT_400HZ # Enable int. 400 Hz source for AM |
| 112 |
sig_gen.am_depth = 50 # Set AM modulation depth to 50% |
| 113 |
... |
| 114 |
sig_gen.am_source = sig_gen.Modulation.OFF # Turn AM off |
| 115 |
|
| 116 |
""", |
| 117 |
validator=strict_discrete_set, |
| 118 |
values=Modulation, |
| 119 |
) |
| 120 |
|
| 121 |
fm_deviation = Instrument.setting( |
| 122 |
"FM %3.1fKZ", |
| 123 |
""" |
| 124 |
Set the peak deviation in kHz for the FM function, |
| 125 |
useable range 0.1 - 400 kHz |
| 126 |
|
| 127 |
*NOTE*: |
| 128 |
the maximum usable deviation is depending on the output frequency, refer to the |
| 129 |
instrument documentation for further detail. |
| 130 |
|
| 131 |
""", |
| 132 |
validator=strict_range, |
| 133 |
values=[0.1, 400], |
| 134 |
) |
| 135 |
|
| 136 |
fm_source = Instrument.setting( |
| 137 |
"FM S%i", |
| 138 |
""" |
| 139 |
Set the source for the FM function with :attr:`Modulation` enumeration. |
| 140 |
|
| 141 |
========== ======= |
| 142 |
Value Meaning |
| 143 |
========== ======= |
| 144 |
OFF no modulation active |
| 145 |
INT_400HZ internal 400 Hz modulation source |
| 146 |
INT_1000HZ internal 1000 Hz modulation source |
| 147 |
EXTERNAL External source, AC coupling |
| 148 |
DC_FM External source, DC coupling (FM only) |
| 149 |
========== ======= |
| 150 |
|
| 151 |
*Note:* |
| 152 |
* AM & FM can be active at the same time |
| 153 |
* only one internal source can be active at the time |
| 154 |
* use "OFF" to deactivate FM |
| 155 |
* refer to the documentation rearding details on use of DC FM mode |
| 156 |
|
| 157 |
usage example: |
| 158 |
|
| 159 |
.. code-block:: python |
| 160 |
|
| 161 |
sig_gen = HP8657B("GPIB::7") |
| 162 |
... |
| 163 |
sig_gen.fm_source = sig_gen.Modulation.EXTERNAL # Enable external source for FM |
| 164 |
sig_gen.fm_deviation = 15 # Set FM peak deviation to 15 kHz |
| 165 |
... |
| 166 |
sig_gen.fm_source = sig_gen.Modulation.OFF # Turn FM off |
| 167 |
|
| 168 |
""", |
| 169 |
validator=strict_discrete_set, |
| 170 |
values=Modulation, |
| 171 |
) |
| 172 |
|
| 173 |
frequency = Instrument.setting( |
| 174 |
"FR %10.0f HZ", |
| 175 |
""" |
| 176 |
Set the output frequency of the instrument in Hz. |
| 177 |
|
| 178 |
For the 8567B the valid range is 100 kHz to 2060 MHz. |
| 179 |
""", |
| 180 |
validator=strict_range, |
| 181 |
values=[1.0E5, 2.060E9], |
| 182 |
) |
| 183 |
|
| 184 |
level = Instrument.setting( |
| 185 |
"AP %g DM", |
| 186 |
""" |
| 187 |
Set the output level in dBm. |
| 188 |
|
| 189 |
For the 8657B the range is -143.5 to +17 dBm/ |
| 190 |
|
| 191 |
""", |
| 192 |
validator=strict_range, |
| 193 |
values=[-143.5, 17.0], |
| 194 |
) |
| 195 |
|
| 196 |
level_offset = Instrument.setting( |
| 197 |
"AO %g DB", |
| 198 |
""" |
| 199 |
Set the output offset in dB, usable range -199 to +199 dB. |
| 200 |
|
| 201 |
""", |
| 202 |
validator=strict_range, |
| 203 |
values=[-199.0, 199.0], |
| 204 |
) |
| 205 |
|
| 206 |
output_enabled = Instrument.setting( |
| 207 |
"R%d", |
| 208 |
""" |
| 209 |
Control whether the output is enabled. |
| 210 |
""", |
| 211 |
validator=strict_discrete_set, |
| 212 |
values={False: 2, True: 3}, |
| 213 |
map_values=True |
| 214 |
) |
| 215 |
|
| 216 |
def reset(self): |
| 217 |
self.adapter.connection.clear() |
| 218 |
|
| 219 |
def shutdown(self): |
| 220 |
self.adapter.connection.clear() |
| 221 |
self.output_enabled = False |
| 222 |
self.adapter.connection.close() |
| 223 |
super().shutdown() |