| 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 |
import numpy as np |
| 27 |
from pymeasure.instruments import Instrument, SCPIUnknownMixin |
| 28 |
from pymeasure.instruments.validators import strict_discrete_set, strict_range |
| 29 |
|
| 30 |
log = logging.getLogger(__name__) |
| 31 |
log.addHandler(logging.NullHandler()) |
| 32 |
|
| 33 |
WL_RANGE = [1480, 1620] |
| 34 |
LOCK_PW = 1234 |
| 35 |
|
| 36 |
|
| 37 |
class KeysightN7776C(SCPIUnknownMixin, Instrument): |
| 38 |
""" |
| 39 |
This represents the Keysight N7776C Tunable Laser Source interface. |
| 40 |
|
| 41 |
.. code-block:: python |
| 42 |
|
| 43 |
laser = N7776C(address) |
| 44 |
laser.sweep_wl_start = 1550 |
| 45 |
laser.sweep_wl_stop = 1560 |
| 46 |
laser.sweep_speed = 1 |
| 47 |
laser.sweep_mode = 'CONT' |
| 48 |
laser.output_enabled = 1 |
| 49 |
while laser.sweep_state == 1: |
| 50 |
log.info('Sweep in progress.') |
| 51 |
laser.output_enabled = 0 |
| 52 |
|
| 53 |
""" |
| 54 |
|
| 55 |
def __init__(self, adapter, name="N7776C Tunable Laser Source", **kwargs): |
| 56 |
super().__init__( |
| 57 |
adapter, name, **kwargs) |
| 58 |
|
| 59 |
locked = Instrument.control( |
| 60 |
':LOCK?', ':LOCK %g,' + str(LOCK_PW), |
| 61 |
"""Control the lock state (True/False) of the laser source. (bool)""", |
| 62 |
validator=strict_discrete_set, |
| 63 |
map_values=True, |
| 64 |
values={True: 1, False: 0} |
| 65 |
) |
| 66 |
|
| 67 |
output_enabled = Instrument.control( |
| 68 |
'SOUR0:POW:STAT?', 'SOUR0:POW:STAT %g', |
| 69 |
"""Control the state (on/off) of the laser source (bool)""", |
| 70 |
validator=strict_discrete_set, |
| 71 |
map_values=True, |
| 72 |
values={True: 1, False: 0} |
| 73 |
) |
| 74 |
|
| 75 |
_output_power_mW = Instrument.control( |
| 76 |
'SOUR0:POW?', 'SOUR0:POW %f mW', |
| 77 |
"""Control the laser output power in mW. (float)""", |
| 78 |
get_process=lambda v: v * 1e3 |
| 79 |
) |
| 80 |
|
| 81 |
_output_power_dBm = Instrument.control( |
| 82 |
'SOUR0:POW?', 'SOUR0:POW %f dBm', |
| 83 |
"""Control the laser output power in dBm. (float)""" |
| 84 |
) |
| 85 |
|
| 86 |
_output_power_unit = Instrument.control( |
| 87 |
'SOUR0:POW:UNIT?', 'SOUR0:POW:UNIT %g', |
| 88 |
"""Control the power unit used internally by the laser. (str)""", |
| 89 |
map_values=True, |
| 90 |
values={'dBm': 0, 'mW': 1} |
| 91 |
) |
| 92 |
|
| 93 |
@property |
| 94 |
def output_power_mW(self): |
| 95 |
"""Control the output power in mW""" |
| 96 |
self._output_power_unit = 'mW' |
| 97 |
return self._output_power_mW |
| 98 |
|
| 99 |
@output_power_mW.setter |
| 100 |
def output_power_mW(self, new_power): |
| 101 |
self._output_power_mW = new_power |
| 102 |
|
| 103 |
@property |
| 104 |
def output_power_dBm(self): |
| 105 |
"""Control the output power in dBm.""" |
| 106 |
self._output_power_unit = 'dBm' |
| 107 |
return self._output_power_dBm |
| 108 |
|
| 109 |
@output_power_dBm.setter |
| 110 |
def output_power_dBm(self, new_power): |
| 111 |
self._output_power_dBm = new_power |
| 112 |
|
| 113 |
trigger_out = Instrument.control( |
| 114 |
'TRIG0:OUTP?', 'TRIG0:OUTP %s', |
| 115 |
""" Control if and at which point in a sweep cycle an output trigger |
| 116 |
is generated and arms the module. """, |
| 117 |
validator=strict_discrete_set, |
| 118 |
values=['DIS', 'STF', 'SWF', 'SWST'] |
| 119 |
) |
| 120 |
|
| 121 |
trigger_in = Instrument.control( |
| 122 |
'TRIG0:INP?', 'TRIG0:INP %s', |
| 123 |
"""Control the incoming trigger response and arm the module.""", |
| 124 |
validator=strict_discrete_set, |
| 125 |
values=['IGN', 'NEXT', 'SWS']) |
| 126 |
|
| 127 |
wavelength = Instrument.control( |
| 128 |
'sour0:wav?', 'sour0:wav %fnm', |
| 129 |
"""Control absolute wavelength of the output light (in nanometers)""", |
| 130 |
validator=strict_range, |
| 131 |
values=WL_RANGE, |
| 132 |
get_process=lambda v: v * 1e9) |
| 133 |
|
| 134 |
sweep_wl_start = Instrument.control( |
| 135 |
'sour0:wav:swe:star?', 'sour0:wav:swe:star %fnm', |
| 136 |
"""Control Start Wavelength (in nanometers) for a sweep.""", |
| 137 |
validator=strict_range, |
| 138 |
values=WL_RANGE, |
| 139 |
get_process=lambda v: v * 1e9) |
| 140 |
|
| 141 |
sweep_wl_stop = Instrument.control('sour0:wav:swe:stop?', 'sour0:wav:swe:stop %fnm', |
| 142 |
"""Control End Wavelength (in nanometers) for a sweep.""", |
| 143 |
validator=strict_range, |
| 144 |
values=WL_RANGE, |
| 145 |
get_process=lambda v: v * 1e9) |
| 146 |
|
| 147 |
sweep_step = Instrument.control('sour0:wav:swe:step?', 'sour0:wav:swe:step %fnm', |
| 148 |
"""Control step width of the sweep (in nanometers).""", |
| 149 |
validator=strict_range, |
| 150 |
values=[0.0001, WL_RANGE[1] - WL_RANGE[0]], |
| 151 |
get_process=lambda v: v * 1e9) |
| 152 |
sweep_speed = Instrument.control('sour0:wav:swe:speed?', 'sour0:wav:swe:speed %fnm/s', |
| 153 |
"""Control speed of the sweep (in nanometers per second).""", |
| 154 |
validator=strict_discrete_set, |
| 155 |
values=[0.5, 1, 50, 80, 200], |
| 156 |
get_process=lambda v: v * 1e9) |
| 157 |
sweep_mode = Instrument.control('sour0:wav:swe:mode?', 'sour0:wav:swe:mode %s', |
| 158 |
"""Control sweep mode of the swept laser source """, |
| 159 |
validator=strict_discrete_set, |
| 160 |
values=['STEP', 'MAN', 'CONT']) |
| 161 |
sweep_twoway = Instrument.control('sour0:wav:swe:rep?', 'sour0:wav:swe:rep %s', |
| 162 |
"""Control the repeat mode. Applies in stepped,continuous and |
| 163 |
manual sweep mode.""", |
| 164 |
validator=strict_discrete_set, |
| 165 |
map_values=True, |
| 166 |
values={False: 'ONEW', True: 'TWOW'}) |
| 167 |
_sweep_params_consistent = Instrument.measurement( |
| 168 |
'sour0:wav:swe:chec?', |
| 169 |
"""Get whether the currently set sweep parameters (sweep mode, sweep start, |
| 170 |
stop, width, etc.) are consistent. If there is a |
| 171 |
sweep configuration problem, the laser source is not |
| 172 |
able to pass a wavelength sweep.""") |
| 173 |
|
| 174 |
sweep_points = Instrument.measurement( |
| 175 |
'sour0:read:points? llog', |
| 176 |
"""Get the number of datapoints that the :READout:DATA? |
| 177 |
command will return.""") |
| 178 |
|
| 179 |
sweep_state = Instrument.control( |
| 180 |
'sour0:wav:swe?', 'sour0:wav:swe %g', |
| 181 |
"""Control state of the wavelength sweep. Stops, starts, pauses or continues a |
| 182 |
wavelength sweep. Possible state values are |
| 183 |
0 (not running), |
| 184 |
1 (running) and |
| 185 |
2 (paused). |
| 186 |
Refer to the N7776C user manual for exact usage of the paused option. """, |
| 187 |
validator=strict_discrete_set, |
| 188 |
values=[0, 1, 2]) |
| 189 |
|
| 190 |
wl_logging = Instrument.control('SOUR0:WAV:SWE:LLOG?', 'SOUR0:WAV:SWE:LLOG %g', |
| 191 |
"""Control State (on/off) of the lambda logging feature of the |
| 192 |
laser source.""", |
| 193 |
validator=strict_discrete_set, |
| 194 |
map_values=True, |
| 195 |
values={True: 1, False: 0}) |
| 196 |
|
| 197 |
def valid_sweep_params(self): |
| 198 |
response = int(self._sweep_params_consistent[0]) |
| 199 |
if response == 0: |
| 200 |
return True |
| 201 |
elif response == 368: |
| 202 |
log.warning('End Wavelength <= Start Wavelength.') |
| 203 |
elif response == 369: |
| 204 |
log.warning('Sweep time too small.') |
| 205 |
elif response == 370: |
| 206 |
log.warning('Sweep time too big.') |
| 207 |
elif response == 371: |
| 208 |
log.warning('Trigger Frequency too large.') |
| 209 |
elif response == 372: |
| 210 |
log.warning('Stepsize too small.') |
| 211 |
elif response == 373 or response == 378: |
| 212 |
log.warning('Number of triggers exceeds allowed limit.') |
| 213 |
elif response == 374: |
| 214 |
log.warning('The only allowed modulation source with lambda logging \ |
| 215 |
function is coherence control.') |
| 216 |
elif response == 375: |
| 217 |
log.warning('Lambda logging only works Step Finished output trigger configuration') |
| 218 |
elif response == 376: |
| 219 |
log.warning('Lambda logging can only be done in continuous sweep mode') |
| 220 |
elif response == 377: |
| 221 |
log.warning('The step size must be a multiple of the smallest possible step size') |
| 222 |
elif response == 379: |
| 223 |
log.warning('Continuous Sweep and Modulation on.') |
| 224 |
elif response == 380: |
| 225 |
log.warning('Start Wavelength is too small.') |
| 226 |
elif response == 381: |
| 227 |
log.warning('End Wavelength is too large.') |
| 228 |
else: |
| 229 |
log.warning('Unknown Error!') |
| 230 |
return False |
| 231 |
|
| 232 |
def next_step(self): |
| 233 |
""" |
| 234 |
Performs the next sweep step in stepped sweep if it is paused or in manual mode. |
| 235 |
""" |
| 236 |
self.write('sour0:wav:swe:step:next') |
| 237 |
|
| 238 |
def previous_step(self): |
| 239 |
""" |
| 240 |
Performs one sweep step backwards in stepped sweep if its paused or in manual mode. |
| 241 |
""" |
| 242 |
self.write('sour0:wav:swe:step:prev') |
| 243 |
|
| 244 |
def get_wl_data(self): |
| 245 |
""" |
| 246 |
Function returning the wavelength data logged in the internal memory of the laser |
| 247 |
""" |
| 248 |
# Using pyvisa's method bypassing the normal read. |
| 249 |
return np.array(self.adapter.connection.query_binary_values('sour0:read:data? llog', |
| 250 |
datatype=u'd')) |
| 251 |
|
| 252 |
def close(self): |
| 253 |
""" |
| 254 |
Fully closes the connection to the instrument through the adapter connection. |
| 255 |
""" |
| 256 |
self.adapter.close() |