Debian Codegraph @

pymeasure/instruments/ipgphotonics/yar.py

raw
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 IntFlag
27
28 from pymeasure.instruments import Instrument, validators
29 from pyvisa.constants import Parity, StopBits
30
31
32 log = logging.getLogger(__name__)
33 log.addHandler(logging.NullHandler())
34
35
36 def emission_validator(value, values):
37 if value is True:
38 return "ON"
39 elif value is False:
40 return "OFF"
41 raise ValueError(f"Value is {value}, but a boolean or 'ON' or 'OFF' required.")
42
43
44 def setpoint_validator(value, values):
45 if value == 0:
46 return value
47 else:
48 return validators.strict_range(value, values)
49
50
51 def power_get_process_generator(minimum):
52 """Generate a get_process for the power property."""
53 def get_process(value):
54 if isinstance(value, float):
55 return value
56 elif value == "Off":
57 return 0
58 elif value == "Low":
59 return minimum
60 else:
61 return value
62 return get_process
63
64
65 class YAR(Instrument):
66 """Communication with the YAR fiber amplifier series by IPG Photonics.
67
68 This is the RS232 command set. GPIB has different commands.
69 """
70
71 def __init__(self, adapter, name="YAR fiber amplifier", **kwargs):
72 """Establish communication with the device."""
73 kwargs.setdefault("write_termination", "\r")
74 kwargs.setdefault("read_termination", "\r")
75 super().__init__(adapter,
76 name=name,
77 includeSCPI=False,
78 asrl={'parity': Parity.none, 'stop_bits': StopBits.one},
79 **kwargs)
80
81 # Commands are 3-4 letters, followed by a parameter, a separation
82 # by space is option. Commands are case-insensitive.
83 # Response is command echoed back, followed by ': ' and the return
84 # value.
85
86 # get valid range of power setpoint:
87 self.power_setpoint_values = self.power_range
88 self.power_get_process = power_get_process_generator(self.minimum_display_power)
89
90 class Status(IntFlag):
91 EMISSION = 0x1 # emission is fully on
92 STARTUP_DELAY = 0x2 # it is in 3 s startup
93 HIGH_TEMPERATURE = 1 << 16
94 HIGH_BACKREFLECTION = 1 << 17
95 UNEXPECTED_EMISSION = 1 << 19
96 SEEDLASER_FAIL = 1 << 20
97
98 def read(self):
99 """Read an instrument answer and check whether it is an error."""
100 reply = super().read().split(":")
101 if reply[0] == "ERR":
102 raise ConnectionError(f"Reading error '{reply}'.")
103 else:
104 return reply[-1].strip()
105
106 def check_set_errors(self):
107 """Check for errors after having set a property.
108
109 Called if :code:`check_set_errors=True` is set for that property.
110 """
111 try:
112 self.read()
113 except ConnectionError as exc:
114 log.exception("Setting a property failed.", exc_info=exc)
115 raise
116 else:
117 return []
118
119 # COMMUNICATION FUNCTIONS
120
121 @property
122 def id(self):
123 """Get the model number."""
124 return self.values("RMN")[0]
125
126 @property
127 def status(self):
128 """Get the current status."""
129 got = int(self.values("STA")[0])
130 return self.Status(got)
131
132 emission_enabled = Instrument.control(
133 "STA",
134 "EM%s",
135 """Control emission of the amplifier (bool).""",
136 cast=int,
137 values=("ON", "OFF"),
138 validator=emission_validator,
139 get_process=lambda v: bool(v & YAR.Status.EMISSION),
140 check_set_errors=True,
141 )
142
143 power = Instrument.measurement(
144 "ROP",
145 "Measure current output power in W.",
146 get_process=power_get_process_generator(0.1),
147 dynamic=True,
148 )
149
150 @property
151 def power_range(self):
152 """Get the power limits in W."""
153 low = self.values("RNP")[0]
154 high = self.values("RMP")[0]
155 return [low, high]
156
157 power_setpoint = Instrument.control(
158 "RPS", "SPS %g", """Control output power setpoint in W.""",
159 values=(1, 2),
160 validator=setpoint_validator,
161 check_set_errors=True,
162 dynamic=True,
163 )
164
165 current = Instrument.measurement("RDC", """Measure the diode current in A.""")
166
167 temperature = Instrument.measurement("RCT", """Measure case temperature in °C.""")
168
169 wavelength_temperature = Instrument.control(
170 "RWA", "SWA %g", """Control temperature in °C for seed wavelength control.""",
171 check_set_errors=True)
172
173 temperature_seed = Instrument.measurement(
174 "RST", "Measure current seed temperature in °C")
175
176 firmware = Instrument.measurement("RFV", """Get firmware version""", cast=str)
177
178 maximum_case_temperature = Instrument.measurement(
179 "RMT", """Measure the maximum temperature for the optical module in °C.""")
180
181 minimum_display_power = Instrument.measurement(
182 "RDPT", """Measure the minimum displayable output power in W.""")
183
184 def clear(self):
185 """Reset all errors."""
186 return self.ask("RERR")