| 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 ctypes |
| 26 |
import logging |
| 27 |
|
| 28 |
from enum import Enum |
| 29 |
from pymeasure.instruments.hp.hplegacyinstrument import HPLegacyInstrument, StatusBitsBase |
| 30 |
from pymeasure.instruments.validators import strict_discrete_set, strict_range |
| 31 |
|
| 32 |
log = logging.getLogger(__name__) |
| 33 |
log.addHandler(logging.NullHandler()) |
| 34 |
|
| 35 |
c_uint8 = ctypes.c_uint8 |
| 36 |
|
| 37 |
|
| 38 |
class Status(StatusBitsBase): |
| 39 |
""" |
| 40 |
Support-Class with the bit assignments for the 2 status byte(12bits used) of the HP6632A |
| 41 |
""" |
| 42 |
|
| 43 |
_fields_ = [ |
| 44 |
# Byte 1: Function, Range and Number of Digits |
| 45 |
("Error_pending", c_uint8, 1), # bit 7 |
| 46 |
("Overcurrent", c_uint8, 1), # bit 6 |
| 47 |
("not_assigned", c_uint8, 1), # bit 5 |
| 48 |
("Overtempeature", c_uint8, 1), # bit 4 |
| 49 |
("Overvoltage", c_uint8, 1), # bit 3 |
| 50 |
("Unregulated", c_uint8, 1), # bit 2 |
| 51 |
("CCpos", c_uint8, 1), # bit 1 |
| 52 |
("CV", c_uint8, 1), # bit 0 |
| 53 |
|
| 54 |
# Byte 2: Status Bits |
| 55 |
("not_assigned", c_uint8, 4), # bits 16..12 |
| 56 |
("NORM", c_uint8, 1), # bit 11 |
| 57 |
("FAST", c_uint8, 1), # bit 10 |
| 58 |
("CCneg", c_uint8, 1), # bit 9 |
| 59 |
("Inhibit_active", c_uint8, 1), # bit 8 |
| 60 |
|
| 61 |
] |
| 62 |
|
| 63 |
|
| 64 |
limits = { |
| 65 |
"HP6632A": {"Volt_lim": 20.475, "OVP_lim": 22.0, "Cur_lim": 5.118}, |
| 66 |
"HP6633A": {"Volt_lim": 51.118, "OVP_lim": 55.0, "Cur_lim": 2.0475}, |
| 67 |
"HP6634A": {"Volt_lim": 102.38, "OVP_lim": 110.0, "Cur_lim": 1.0238}} |
| 68 |
|
| 69 |
|
| 70 |
class HP6632A(HPLegacyInstrument): |
| 71 |
""" Represents the Hewlett Packard 6632A system power supply |
| 72 |
and provides a high-level interface for interacting |
| 73 |
with the instrument. |
| 74 |
""" |
| 75 |
status_desc = Status |
| 76 |
|
| 77 |
def __init__(self, adapter, name="Hewlett-Packard HP6632A", **kwargs): |
| 78 |
kwargs.setdefault('read_termination', '\r\n') |
| 79 |
kwargs.setdefault('send_end', True) |
| 80 |
super().__init__( |
| 81 |
adapter, |
| 82 |
name, |
| 83 |
**kwargs, |
| 84 |
) |
| 85 |
|
| 86 |
class ERRORS(Enum): |
| 87 |
""" |
| 88 |
Enum class for error messages |
| 89 |
|
| 90 |
""" |
| 91 |
NO_ERR = 0 |
| 92 |
EEPROM = 1 |
| 93 |
PON_2ND = 2 |
| 94 |
DCPON_2MD = 4 |
| 95 |
NORELAY = 5 |
| 96 |
NOTHING_SAY = 8 |
| 97 |
HEADER_EXPECTED = 10 |
| 98 |
UNRECOGNISED_HEADER = 11 |
| 99 |
NUMBER_EXPECTED = 20 |
| 100 |
NUMBER_SYNTAX = 21 |
| 101 |
OUT_OF_RANGE = 22 |
| 102 |
COMMA_EXPECTED = 30 |
| 103 |
TERM_EXPECTED = 31 |
| 104 |
PARAM_OUT = 41 |
| 105 |
V_PGM_ERR = 42 |
| 106 |
I_PGM_ERR = 43 |
| 107 |
OV_PGM_ERR = 44 |
| 108 |
DLY_PGM_ERR = 45 |
| 109 |
MASK_PGM_ERR = 46 |
| 110 |
MULT_CSAVE_ERR = 50 |
| 111 |
EEPROM_CJLSUM_ERR = 51 |
| 112 |
CALMODE_DISABLED = 52 |
| 113 |
CAL_CHNL_ERR = 53 |
| 114 |
CAL_FS_ERR = 54 |
| 115 |
CAL_OFFSET = 55 |
| 116 |
CAL_JMP_ERR = 59 |
| 117 |
|
| 118 |
class ST_ERRORS(Enum): |
| 119 |
""" |
| 120 |
Enum class for selftest errors |
| 121 |
|
| 122 |
""" |
| 123 |
NO_ST_ERR = 0 |
| 124 |
ROM_CKSSUM = 1 |
| 125 |
RAM_TEST = 2 |
| 126 |
HPIB_CHIP = 3 |
| 127 |
HPIB_TIMER_SLOW = 4 |
| 128 |
HPIB_TIMER_FAST = 5 |
| 129 |
PSI_ROM_CHKSUM = 11 |
| 130 |
PSI_RAM_TEST = 12 |
| 131 |
PSI_TIMER_SLOW = 14 |
| 132 |
PSI_TIMER_FAST = 15 |
| 133 |
AD_TEST_HIGH = 16 |
| 134 |
AD_TEST_LOW = 17 |
| 135 |
CCCV_ZERO_HIGH = 18 |
| 136 |
CCCV_ZERO_LOW = 19 |
| 137 |
CV_REF_HIGH = 20 |
| 138 |
CV_REF_LOW = 21 |
| 139 |
CC_REF_HIGH = 22 |
| 140 |
CC_REF_LOW = 23 |
| 141 |
DAC_FAIL = 24 |
| 142 |
EEPROM_CHKSUM = 51 |
| 143 |
|
| 144 |
def check_errors(self): |
| 145 |
""" |
| 146 |
Method to read the error status register |
| 147 |
|
| 148 |
:return error_status: one byte with the error status register content |
| 149 |
:rtype error_status: int |
| 150 |
""" |
| 151 |
# Read the error status register only one time for this method, as |
| 152 |
# the manual states that reading the error status register also clears it. |
| 153 |
current_errors = int(self.ask("ERR?")) |
| 154 |
if current_errors != 0: |
| 155 |
log.error("HP6632 Error detected: %s", self.ERRORS(current_errors)) |
| 156 |
return self.ERRORS(current_errors) |
| 157 |
|
| 158 |
def check_selftest_errors(self): |
| 159 |
""" |
| 160 |
Method to read the error status register |
| 161 |
|
| 162 |
:return error_status: one byte with the error status register content |
| 163 |
:rtype error_status: int |
| 164 |
""" |
| 165 |
# Read the error status register only one time for this method, as |
| 166 |
# the manual states that reading the error status register also clears it. |
| 167 |
current_errors = int(self.ask("TEST?")) |
| 168 |
if current_errors != 0: |
| 169 |
log.error("HP6632 Error detected: %s", self.ERRORS(current_errors)) |
| 170 |
return self.ST_ERRORS(current_errors) |
| 171 |
|
| 172 |
def clear(self): |
| 173 |
""" |
| 174 |
Resets the instrument to power-on default settings |
| 175 |
|
| 176 |
""" |
| 177 |
self.write("CLR") |
| 178 |
|
| 179 |
delay = HPLegacyInstrument.setting( |
| 180 |
"DELAY %g", |
| 181 |
""" |
| 182 |
A float property that changes the reprogamming delay |
| 183 |
Default values: |
| 184 |
8 ms in FAST mode |
| 185 |
80 ms in NORM mode |
| 186 |
|
| 187 |
Values will be rounded to the next 4 ms by the instrument |
| 188 |
|
| 189 |
""", |
| 190 |
validator=strict_range, |
| 191 |
values=[0, 32.768], |
| 192 |
) |
| 193 |
|
| 194 |
display_active = HPLegacyInstrument.setting( |
| 195 |
"DIS %d", |
| 196 |
""" |
| 197 |
A boot property which controls if the display is enabled |
| 198 |
""", |
| 199 |
validator=strict_discrete_set, |
| 200 |
values={False: 0, True: 1}, |
| 201 |
map_values=True |
| 202 |
) |
| 203 |
|
| 204 |
@property |
| 205 |
def status(self): |
| 206 |
""" |
| 207 |
Returns an object representing the current status of the unit. |
| 208 |
|
| 209 |
""" |
| 210 |
# overloading the already existing property because of the different command |
| 211 |
reply = bytearray(int(self.ask("STS?")).to_bytes( |
| 212 |
self.status_bytes_count, "little")) |
| 213 |
return self.status_bits.from_buffer(reply) |
| 214 |
|
| 215 |
id = HPLegacyInstrument.measurement( |
| 216 |
"ID?", |
| 217 |
""" |
| 218 |
Reads the ID of the instrument and returns this value for now |
| 219 |
|
| 220 |
""", |
| 221 |
) |
| 222 |
|
| 223 |
current = HPLegacyInstrument.control( |
| 224 |
"IOUT?", "ISET %g", |
| 225 |
""" |
| 226 |
A floating point property that controls the output current of the device. |
| 227 |
|
| 228 |
""", |
| 229 |
dynamic=True, |
| 230 |
validator=strict_range, |
| 231 |
values=[0, limits["HP6632A"]["Cur_lim"]], |
| 232 |
) |
| 233 |
|
| 234 |
over_voltage_limit = HPLegacyInstrument.setting( |
| 235 |
"OVSET %g", |
| 236 |
""" |
| 237 |
A floationg point property that sets the OVP threshold. |
| 238 |
|
| 239 |
""", |
| 240 |
dynamic=True, |
| 241 |
validator=strict_range, |
| 242 |
values=[0, limits["HP6632A"]["OVP_lim"]], |
| 243 |
) |
| 244 |
|
| 245 |
OCP_enabled = HPLegacyInstrument.setting( |
| 246 |
"OCP %d", |
| 247 |
""" |
| 248 |
A bool property which controls if the OCP (OverCurrent Protection) is enabled |
| 249 |
""", |
| 250 |
validator=strict_discrete_set, |
| 251 |
values={False: 0, True: 1}, |
| 252 |
map_values=True |
| 253 |
) |
| 254 |
|
| 255 |
output_enabled = HPLegacyInstrument.setting( |
| 256 |
"OUT %d", |
| 257 |
""" |
| 258 |
A bool property which controls if the outputis enabled |
| 259 |
""", |
| 260 |
validator=strict_discrete_set, |
| 261 |
values={False: 0, True: 1}, |
| 262 |
map_values=True |
| 263 |
) |
| 264 |
|
| 265 |
@output_enabled.getter |
| 266 |
def output_enabled(self): |
| 267 |
""" |
| 268 |
A bool property which controls if the output is enabled |
| 269 |
""" |
| 270 |
output_status = bool(self.status.CV or self.status.CCpos or |
| 271 |
self.status.CCneg or self.status.Unregulated) |
| 272 |
return output_status |
| 273 |
|
| 274 |
def reset_OVP_OCP(self): |
| 275 |
""" |
| 276 |
Resets Overvoltage and Overcurrent protections |
| 277 |
|
| 278 |
""" |
| 279 |
self.write("RST") |
| 280 |
|
| 281 |
rom_version = HPLegacyInstrument.measurement( |
| 282 |
"ROM?", |
| 283 |
""" |
| 284 |
Reads the ROM id (software version) of the instrument and returns this value for now |
| 285 |
|
| 286 |
""", |
| 287 |
) |
| 288 |
|
| 289 |
SRQ_enabled = HPLegacyInstrument.setting( |
| 290 |
"SRQ %d", |
| 291 |
""" |
| 292 |
A bool property which controls if the SRQ (ServiceReQuest) is enabled |
| 293 |
""", |
| 294 |
validator=strict_discrete_set, |
| 295 |
values={False: 0, True: 1}, |
| 296 |
map_values=True |
| 297 |
) |
| 298 |
|
| 299 |
voltage = HPLegacyInstrument.control( |
| 300 |
"VOUT?", "VSET %g", |
| 301 |
""" |
| 302 |
A floating point proptery that controls the output voltage of the device. |
| 303 |
|
| 304 |
""", |
| 305 |
dynamic=True, |
| 306 |
validator=strict_range, |
| 307 |
values=[0, limits["HP6632A"]["Volt_lim"]], |
| 308 |
) |
| 309 |
|
| 310 |
|
| 311 |
class HP6633A(HP6632A): |
| 312 |
""" Represents the Hewlett Packard 6633A system power supply |
| 313 |
and provides a high-level interface for interacting |
| 314 |
with the instrument. |
| 315 |
""" |
| 316 |
|
| 317 |
def __init__(self, adapter, name="Hewlett Packard HP6633A", **kwargs): |
| 318 |
super().__init__(adapter, name, **kwargs) |
| 319 |
|
| 320 |
current_values = [0, limits["HP6633A"]["Cur_lim"]] |
| 321 |
OVP_values = [0, limits["HP6633A"]["OVP_lim"]] |
| 322 |
voltage_values = [0, limits["HP6633A"]["Volt_lim"]] |
| 323 |
|
| 324 |
|
| 325 |
class HP6634A(HP6632A): |
| 326 |
""" Represents the Hewlett Packard 6634A system power supply |
| 327 |
and provides a high-level interface for interacting |
| 328 |
with the instrument. |
| 329 |
""" |
| 330 |
|
| 331 |
def __init__(self, adapter, name="Hewlett Packard HP6634A", **kwargs): |
| 332 |
super().__init__(adapter, name, **kwargs) |
| 333 |
|
| 334 |
current_values = [0, limits["HP6634A"]["Cur_lim"]] |
| 335 |
OVP_values = [0, limits["HP6634A"]["OVP_lim"]] |
| 336 |
voltage_values = [0, limits["HP6634A"]["Volt_lim"]] |