"""
Created on Mon Feb 14 13:54:49 2022
@author: Martin.Mihaylov
"""
from .BaseInstrument import BaseInstrument
[docs]
class CoBrite(BaseInstrument):
def __init__(self, resource_str: str, visa_library: str = "@py", **kwargs):
"""
This Class is using PyVisa to connect to CoBrite Laser, please install PyVisa.
"""
kwargs.setdefault("query_delay", 0.5)
kwargs.setdefault("read_termination", "\n")
super().__init__(str(resource_str), visa_library=visa_library, **kwargs)
print(self.get_idn())
def _validate_channel(self, channel: int | float | str) -> int:
channel = int(float(channel))
if channel not in [1, 2]:
raise ValueError("Invalid channel number given! CoBrite has only 2 channels (1 or 2).")
return channel
# =============================================================================
# Identify
# =============================================================================
[docs]
def get_identification(self) -> str:
"""
Identification name and model of the instrument.
"""
return self.query("*IDN?")
# =============================================================================
# ASK
# =============================================================================
[docs]
def get_freq_thz(self, chan: int) -> float:
"""
Queries the wavelength setting of a tunable laser port.
Value format is in THz.
Parameters
----------
chan : int
Channel number. Can be 1 or 2. CoBrite have only 2 channels!
Raises
------
ValueError
Error message.
"""
chan = self._validate_channel(chan)
freq = self.query(f"FREQ? 1,1,{chan}")
return float(freq.split(";")[0])
[docs]
def get_wavelength(self, chan: int) -> float:
"""
Queries the wavelength setting of a tunable laser port.
Value format is in Nanometer.
Parameters
----------
chan : int
Channel number. Can be 1 or 2. CoBrite have only 2 channels!
Raises
------
ValueError
Error message.
"""
chan = self._validate_channel(chan)
wav = self.query(f"WAV? 1,1,{chan}")
return float(wav.split(";")[0])
[docs]
def get_offset(self, chan: int) -> float:
"""
Queries the frequency offset setting of a tunable laser port.
Value format is in GHz.
Parameters
----------
chan : int
Channel number. Can be 1 or 2. CoBrite have only 2 channels!
Raises
------
ValueError
Error message.
"""
chan = self._validate_channel(chan)
freq = self.query(f"OFF? 1,1,{chan}")
return float(freq.split(";")[0])
[docs]
def get_laser_output(self, chan: int) -> str:
"""
Query if laser is ON or OFF.
Parameters
----------
chan : int
Channel number. Can be 1 or 2. CoBrite have only 2 channels!
Raises
------
ValueError
Error message.
"""
chan = self._validate_channel(chan)
out = float(self.query(f"STATe? 1,1,{chan}").split(";")[0])
return "ON" if out != 0 else "OFF"
[docs]
def get_power(self, chan: int) -> float:
"""
Queries the optical output power target setting of a tunable laser
port. Value format is in dBm.
Parameters
----------
chan : int
Channel number. Can be 1 or 2. CoBrite have only 2 channels!
Raises
------
ValueError
Error message.
"""
chan = self._validate_channel(chan)
power = self.query(f"POW? 1,1,{chan}")
return float(power.split(";")[0])
[docs]
def get_actual_power(self, chan: int) -> float:
"""
Queries the current optical output power reading of a tunable laser
port. Value format is in dBm.
Parameters
----------
chan : int
Channel number. Can be 1 or 2. CoBrite have only 2 channels!
Raises
------
ValueError
Error message.
"""
chan = self._validate_channel(chan)
apow = self.query(f"APOW? 1,1,{chan}")
return float(apow.split(";")[0])
[docs]
def get_laser_lim(self, chan: int) -> dict[str, float]:
"""
Query maximum tuning Parameters of Laser in location C-S-D in csv
format.
Parameters
----------
chan : int
Channel number. Can be 1 or 2. CoBrite have only 2 channels!
Raises
------
ValueError
Error message.
"""
chan = self._validate_channel(chan)
lim = self.query(f"LIM? 1,1,{chan}")
datasep = lim.split(";")[0].split(",")
data_dict: dict[str, float] = {}
labels = [
"Minimum Frequency",
"Maximum Frequency",
"Fine tuning Range",
"Minimum Power",
"Maximum Power",
]
for i in range(len(datasep)):
data_dict[labels[i]] = float(datasep[i])
return data_dict
[docs]
def get_configuration(self, chan: int) -> dict[str, float | str]:
"""
Query current configuration of Laser in location C-S-D in csv format
Parameters
----------
chan : int
Channel number. Can be 1 or 2. CoBrite have only 2 channels!.
Raises
------
ValueError
Error message.
"""
chan = self._validate_channel(chan)
config = self.query(f":SOURce:CONFiguration? 1,1,{chan}")
datasep = config.split(";")[0].split(",")
if datasep[-1] == "-1":
datasep[-1] = "NO"
else:
datasep[-1] = "YES"
data_dict: dict[str, float | str] = {}
labels = [
"Wavelength",
"Offset",
"Output Power",
"Output state",
"Busy state",
"Dither state",
]
for i in range(int(len(datasep) - 1)):
data_dict[labels[i]] = float(datasep[i])
data_dict["Dither supported"] = datasep[-1]
return data_dict
# =============================================================================
# SET
# =============================================================================
[docs]
def set_power(self, chan: int, value: float) -> None:
"""
Sets the optical output power target setting of a tunable laser port.
Value format is in dBm.
Parameters
----------
chan : int
Channel number. Can be 1 or 2. CoBrite have only 2 channels!.
value : float
Sets the optical output power target setting of a tunable laser port.
Value format is in dBm.
Raises
------
ValueError
Error message.
"""
chan = self._validate_channel(chan)
self.write(f"POW 1,1,{chan},{value}")
[docs]
def set_wavelength(self, chan: int, value: float) -> None:
"""
Sets the wavelength setting of a tunable laser port. Value format
is in Nanometer.
Parameters
----------
chan : int
Channel number. Can be 1 or 2. CoBrite have only 2 channels!.
value : float
Sets the wavelength setting of a tunable laser port. Value format
is in Nanometer.
Raises
------
ValueError
Error message.
"""
chan = self._validate_channel(chan)
self.write(f"WAV 1,1,{chan},{value}")
[docs]
def set_freq_thz(self, chan: int, value: float) -> None:
"""
Sets or queries the wavelength setting of a tunable laser port.
Value format is in Tera Hertz.
Parameters
----------
chan : int
Channel number. Can be 1 or 2. CoBrite have only 2 channels!.
value : float
Sets or queries the wavelength setting of a tunable laser port.
Value format is in Tera Hertz.
Raises
------
ValueError
Error message.
"""
chan = self._validate_channel(chan)
self.write(f"FREQ 1,1,{chan},{value}")
[docs]
def set_laser_output(self, chan: int, state: str | int) -> None:
"""
Set if laser is ON or OFF.
Parameters
----------
chan : int
Channel number. Can be 1 or 2. CoBrite have only 2 channels!.
state : float/int
Set if laser is ON or OFF. Can be integer 0 or 1, but can be a str
ON and OFF.
Raises
------
ValueError
Error message.
"""
parsed_state = self._parse_state(state)
state_val = "1" if parsed_state == "ON" else "0"
chan = self._validate_channel(chan)
self.write(f"STATe 1,1,{chan},{state_val}")
[docs]
def set_offset(self, chan: int, value: float) -> None:
"""
Sets the frequency offset setting of a tunable laser port.
Value format is in Giga Hertz.
Parameters
----------
chan : int
Channel number. Can be 1 or 2. CoBrite have only 2 channels!.
value : float
Sets the frequency offset setting of a tunable laser port.
Value format is in Giga Hertz.
Raises
------
ValueError
Error message.
"""
chan = self._validate_channel(chan)
self.write(f"OFF 1,1,{chan},{value}")
[docs]
def set_configuration(self, chan: int, freq: float, power: float, offset: float) -> None:
"""
Parameters
----------
chan : int
Channel number. Can be 1 or 2. CoBrite have only 2 channels!
freq : float
Sets frequency in Thz format. For example freq = 192.2345
power : float
Sets the power to dBm. For example power = 9.8.
min Power = 8.8
max Power = 17.8
Check ask_LaserLim() for more info.
offset : float
Sets offset Freq in range Ghz.
Raises
------
ValueError
Error message.
"""
chan = self._validate_channel(chan)
self.set_freq_thz(chan, freq)
self.set_power(chan, power)
self.set_offset(chan, offset)