def GetType(self): ''' Return the type of the TLS return 0 for a C band Laser return 2 for a L band Laser ''' from PyApex.Constantes import AP1000_ERROR_SLOT_TYPE_NOT_DEFINED from PyApex.Constantes import SimuTLS_SlotID, AP1000_TLS_CBAND, AP1000_TLS_LBAND from PyApex.Errors import ApexError import re if self.__Simulation: ID = SimuTLS_SlotID else: Command = "SLT[" + str(self.__SlotNumber).zfill(2) + "]:IDN?\n" Send(self.__Connexion, Command) ID = Receive(self.__Connexion) if re.findall(str(AP1000_TLS_CBAND), ID.split("/")[1]) != []: return 0 elif re.findall(str(AP1000_TLS_LBAND), ID.split("/")[1]) != []: return 2 else: self.Off() self.__Connexion.close() raise ApexError(AP1000_ERROR_SLOT_TYPE_NOT_DEFINED, self.__SlotNumber)
def GetType(self): ''' Return the type of the DFB return 0 for a C band Laser return 2 for a L band Laser return 5 for a O band Laser ''' from PyApex.Constantes import AP1000_ERROR_SLOT_TYPE_NOT_DEFINED from PyApex.Constantes import SimuDFB_SlotID, AP1000_DFB_CBAND, AP1000_DFB_LBAND, AP1000_DFB_OBAND from PyApex.Errors import ApexError import re if self.__Simulation: ID = SimuDFB_SlotID else: Command = "SLT[" + str(self.__SlotNumber).zfill(2) + "]:IDN?\n" Send(self.__Connexion, Command) ID = Receive(self.__Connexion) if re.findall(str(AP1000_DFB_CBAND), ID.split("/")[1]) != []: return 0 elif re.findall(str(AP1000_DFB_LBAND), ID.split("/")[1]) != []: return 2 elif re.findall(str(AP1000_DFB_OBAND), ID.split("/")[1]) != []: return 5 else: self.Off() self.__Connexion.close() raise ApexError(AP1000_ERROR_SLOT_TYPE_NOT_DEFINED, self.__SlotNumber)
def GetType(self, type="d"): ''' Return the type of the EFA if type = 'd' (default), return a digit : - 0 for Booster - 1 for In-Line - 2 for Pre-Ampli if type = 'c', return the option character : - 'A' for Booster - 'B' for In-Line - 'C' for Pre-Ampli if type = 's', return a string : - "Booster" for Booster - "In-Line" for In-Line - "Pre-Amplifier" for Pre-Ampli ''' from PyApex.Constantes import AP1000_ERROR_SLOT_TYPE_NOT_DEFINED from PyApex.Constantes import SimuEFA_SlotID from PyApex.Errors import ApexError import re if self.__Simulation: ID = SimuEFA_SlotID else: Command = "SLT[" + str(self.__SlotNumber).zfill(2) + "]:IDN?\n" Send(self.__Connexion, Command) ID = Receive(self.__Connexion) if re.findall("A", ID.split("/")[2].split("-")[2]) != []: if type.lower() == "c": return "A" elif type.lower() == "s": return "Booster" else: return 0 elif re.findall("B", ID.split("/")[2].split("-")[2]) != []: if type.lower() == "c": return "B" elif type.lower() == "s": return "In-Line" else: return 1 elif re.findall("C", ID.split("/")[2].split("-")[2]) != []: if type.lower() == "c": return "C" elif type.lower() == "s": return "Pre-Amplifier" else: return 2 else: self.__Connexion.close() raise ApexError(AP1000_ERROR_SLOT_TYPE_NOT_DEFINED, self.__SlotNumber)
def GetStateOfPolarization(self): ''' Gets the State Of Polarization for the selected path and the selected wavelength ''' from random import random from math import sqrt Values = [] if not self.__Simulation: Command = "POLSOP?\n" Send(self.__Connexion, Command) Str = Receive(self.__Connexion, 64)[:-1] for v in Str.split(" "): try: Values.append(float(v)) except: pass else: S = [] S.append(1.0) for i in range(3): S.append(2.0 * random() - 1.0) S0 = sqrt(S[0]**2 + S[1]**2 + S[2]**2) for i in range(4): Values.append(S[i] / S[0]) return Values
def GetType(self, type="d"): ''' Return the type of the OSW if type = 'd' (default), return a digit : - 0 for 1X2 or 2X2 - 1 for 1X4 - 2 for 1X8 if type = 's', return a string : - "NX2" for 1X2 or 2X2 - "1X4" for 1X4 - "1X8" for 1X8 ''' from PyApex.Constantes import AP1000_ERROR_SLOT_TYPE_NOT_DEFINED from PyApex.Constantes import SimuOSW_SlotID from PyApex.Errors import ApexError import re if self.__Simulation: ID = SimuOSW_SlotID else: Command = "SLT[" + str(self.__SlotNumber).zfill(2) + "]:IDN?\n" Send(self.__Connexion, Command) ID = Receive(self.__Connexion) if re.findall("x2", ID.split("/")[2].split("-")[3].lower()) != []: if type.lower() == "s": return "NX2" else: return 0 elif re.findall("x4", ID.split("/")[2].split("-")[3].lower()) != []: if type.lower() == "s": return "1X4" else: return 1 elif re.findall("x8", ID.split("/")[2].split("-")[3].lower()) != []: if type.lower() == "s": return "1X8" else: return 2 else: self.__Connexion.close() raise ApexError(AP1000_ERROR_SLOT_TYPE_NOT_DEFINED, self.__SlotNumber)
def LineWidth(self, TraceNumber=1, Get="width"): ''' Gets the 3-db line width of the selected trace TraceNumber is an integer between 1 (default) and 6 ThresholdValue is a float expressed in dB Get is a string between the following values: - Get = "WIDTH" : only the line width is returned (default) - Get = "CENTER" : only the line width center is returned - Get = "LEVEL" : only the line width peak level is returned - Get = "ALL" : all line width values are returned in a list ''' from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE, APXXXX_ERROR_ARGUMENT_VALUE from PyApex.Errors import ApexError if not isinstance(TraceNumber, int): raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "TraceNumber") sys.exit() if not TraceNumber in self.__Validtracenumbers: raise ApexError(APXXXX_ERROR_ARGUMENT_VALUE, "TraceNumber") sys.exit() if not self.__Simulation: Command = "SPLWTH" + str(TraceNumber) + "_3.0\n" Send(self.__Connexion, Command) Str = Receive(self.__Connexion, 64)[:-1] Values = [] Str = Str.split("_") for s in Str: for v in s.split(" "): if v.lower() not in ["dbm", "mw", "nm", "ghz"]: try: Values.append(float(v)) except: pass while len(Values) < 3: Values.append(0.0) else: Values = [0.100, 1550.000, 2.25] if str(Get).lower() == "all": return Values elif str(Get).lower() == "center": return Values[1] elif str(Get).lower() == "level": return Values[2] else: return Values[0]
def GetMarkers(self, TraceNumber=1, Axis='y'): ''' Gets the X-axis or Y-axis markers of a selected trace TraceNumber is an integer between 1 (default) and 6 Axis is a string or an integer for selecting the axis: Axis = 0 or 'X' : get the X-axis values of the markers Axis = 1 or 'Y' : get the Y-axis values of the markers (default) ''' from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE, APXXXX_ERROR_ARGUMENT_VALUE from PyApex.Errors import ApexError if not isinstance(Axis, (int, str)): raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "Axis") sys.exit() if not Axis in [0, 1] and not str(Axis).lower() in ['x', 'y'] : raise ApexError(APXXXX_ERROR_ARGUMENT_VALUE, "Axis") sys.exit() if not isinstance(TraceNumber, int): raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "TraceNumber") sys.exit() if not TraceNumber in self.__Validtracenumbers: raise ApexError(APXXXX_ERROR_ARGUMENT_VALUE, "TraceNumber") sys.exit() if str(Axis).lower() == 'x': Axis = 0 else: Axis = 1 Markers = [] if not self.__Simulation: if Axis: Command = "SPDATAMKRY" + str(TraceNumber) + "\n" else: Command = "SPDATAMKRX" + str(TraceNumber) + "\n" Send(self.__Connexion, Command) Str = Receive(self.__Connexion, 64)[:-1] Str = Str.split(" ") Str = Str[1:] for v in Str: if v.lower() not in ["dbm", "mw", "nm", "ghz"]: try: Markers.append(float(v)) except: pass return Markers
def GetMarkers(self, TraceNumber=1, Axis='y'): ''' Gets the X-axis or Y-axis markers of a selected trace TraceNumber is an integer between 1 (default) and 6 Axis is a string or an integer for selecting the axis: Axis = 0 or 'X' : get the X-axis values of the markers Axis = 1 or 'Y' : get the Y-axis values of the markers (default) ''' from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE, APXXXX_ERROR_ARGUMENT_VALUE from PyApex.Errors import ApexError if not isinstance(Axis, (int, str)): raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "Axis") sys.exit() if not Axis in [0, 1] and not str(Axis).lower() in ['x', 'y']: raise ApexError(APXXXX_ERROR_ARGUMENT_VALUE, "Axis") sys.exit() if not isinstance(TraceNumber, int): raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "TraceNumber") sys.exit() if not TraceNumber in self.__Validtracenumbers: raise ApexError(APXXXX_ERROR_ARGUMENT_VALUE, "TraceNumber") sys.exit() if str(Axis).lower() == 'x': Axis = 0 else: Axis = 1 Markers = [] if not self.__Simulation: if Axis: Command = "SPDATAMKRY" + str(TraceNumber) + "\n" else: Command = "SPDATAMKRX" + str(TraceNumber) + "\n" Send(self.__Connexion, Command) Str = Receive(self.__Connexion, 64)[:-1] Str = Str.split(" ") Str = Str[1:] for v in Str: if v.lower() not in ["dbm", "mw", "nm", "ghz"]: try: Markers.append(float(v)) except: pass return Markers
def ListBands(self): ''' Gets a list of all optical bands in the AP2XXX equipment. The optical band choice is only available for AP2X8X ''' if self.__Simulation: Bands = ["O", "C&L"] else: Send(self.Connexion, "LSBANDS?\n") Bands = Receive(self.Connexion)[:-1] Bands = Bands.split(",") for i in range(len(Bands)): Bands[i] = Bands[i].replace("&&", "&") Bands[i] = Bands[i].strip() return Bands
def GetPolarimeterIdentity(self): ''' Gets the serial number of the polarimeter board !!! FOR CALIBRATION ONLY !!! ''' Values = [] if not self.__Simulation: Command = "POLIDN?\n" Send(self.__Connexion, Command) Str = Receive(self.__Connexion, 64)[:-1] for value in Str.split(" "): Values.append(value) else: Values = ["XX-AB3510-XSIMUX", "1.0", "1.1"] return Values
def ListModes(self): ''' Gets a list of all modes in the AP2XXX equipment. These modes are expressed as string. The index of the element in the list follows the list in the AP2XXX menu box ''' if self.__Simulation: Modes = [ "Apex Start", "General Settings", "Powermeter", "T.L.S", "O.S.A." ] else: Send(self.Connexion, "LSMODES?\n") Modes = Receive(self.Connexion)[:-1] Modes = Modes.split(",") for i in range(len(Modes)): Modes[i] = Modes[i].strip() return Modes
def GetChannels(self): ''' Return the type(s) of the PWM in a list return 1 for a Standard PWM return 3 for a High Power PWM ''' from PyApex.Constantes import SimuPWM_SlotID, AP1000_PWM_CHTYPE if self.__Simulation: ID = SimuPWM_SlotID else: Command = "SLT[" + str(self.__SlotNumber).zfill(2) + "]:IDN?\n" Send(self.__Connexion, Command) ID = Receive(self.__Connexion) Channels = [] for c in ID.split("/")[2].split("-")[3]: for k, v in AP1000_PWM_CHTYPE.items(): if c == k: Channels.append(v) return Channels
def GetPower(self, Polar=0): ''' Get the power measured by the Powermeter equipment The return power is expressed in the unit defined by the GetUnit() method Polar is the polarization channel : - 0 : Total power (default) - 1 : Power of polarization channel n°1 - 2 : Power of polarization channel n°2 ''' from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE, APXXXX_ERROR_ARGUMENT_VALUE from PyApex.Constantes import APXXXX_ERROR_VARIABLE_NOT_DEFINED from PyApex.Errors import ApexError from random import random if not isinstance(Polar, (int)): self.__Connexion.close() raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "Polar") if self.__Simulation: if self.__Unit.lower() == "dbm": Power = 60.0 * random() - 50.0 elif self.__Unit.lower() == "mw": Power = 10.0 * random() else: self.__Connexion.close() raise ApexError(APXXXX_ERROR_VARIABLE_NOT_DEFINED, "self.__Unit") else: Command = "SPMEASDETECTORDBM1\n" Send(self.__Connexion, Command) Power = Receive(self.__Connexion)[:-1] for p in Power.split("_"): try: Power = float(p) except: pass return Power
def GetPolarimeterRawPower(self): ''' Gets the power values in binary from the 4 detectors of the polarimeter !!! FOR CALIBRATION ONLY !!! ''' from random import randint Values = [] if not self.__Simulation: Command = "POLRAWPOWER?\n" Send(self.__Connexion, Command) Str = Receive(self.__Connexion, 64)[:-1] for v in Str.split(" "): try: Values.append(int(v)) except: pass else: for i in range(4): Values.append(randint(0, 2**14)) return Values
def GetPolarimeterPower(self): ''' Gets the power values in dBm from the 4 detectors of the polarimeter !!! FOR CALIBRATION ONLY !!! ''' from random import random Values = [] if not self.__Simulation: Command = "POLPOWER?\n" Send(self.__Connexion, Command) Str = Receive(self.__Connexion, 64)[:-1] for v in Str.split(" "): try: Values.append(float(v)) except: pass else: for i in range(4): Values.append(80.0 * random() - 70.0) return Values
def GetData(self, Scale="log", TraceNumber=1): ''' Get the spectrum data of a measurement returns a 2D list [Y-axis Data, X-Axis Data] Scale is a string which can be : - "log" : get the Y-Axis Data in dBm (default) - "lin" : get the Y-Axis Data in mW TraceNumber is an integer between 1 (default) and 6 ''' from random import random from math import log10 from PyApex.Constantes import SimuAP2XXX_StartWavelength, SimuAP2XXX_StopWavelength from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE from PyApex.Errors import ApexError if not isinstance(Scale, str): raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "Scale") sys.exit() if not isinstance(TraceNumber, (float, int)): raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "TraceNumber") sys.exit() self.__NPoints = self.GetNPoints() if not self.__Simulation: YData = [] XData = [] if Scale.lower() == "lin": Command = "SPDATAL" + str(int(TraceNumber)) + "\n" else: Command = "SPDATAD" + str(int(TraceNumber)) + "\n" Send(self.__Connexion, Command) YStr = Receive(self.__Connexion, 20 * self.__NPoints)[:-1] YStr = YStr.split(" ") for s in YStr: try: YData.append(float(s)) except: YData.append(0.0) Command = "SPDATAWL" + str(TraceNumber) + "\n" Send(self.__Connexion, Command) XStr = Receive(self.__Connexion, 20 * self.__NPoints)[:-1] XStr = XStr.split(" ") for s in XStr: try: XData.append(float(s)) except: XData.append(0.0) else: YData = [NPoints] XData = [NPoints] DeltaX = (self.__StopWavelength - self.__StartWavelength) / self.__NPoints for i in range(0, self.__NPoints): if Scale.lower() == "lin": YData.append(random()) else: YData.append(80.0 * random() - 70.0) XData.append(self.__StartWavelength + i * DeltaX) return [YData[1:], XData[1:]]
def GetData(self, Scale="log", TraceNumber=1): ''' Get the spectrum data of a measurement on the OSA Fast-Sweep returns a 2D list [Y-axis Data, X-Axis Data] Scale is a string which can be : - "log" : get the Y-Axis Data in dBm (default) - "lin" : get the Y-Axis Data in mW TraceNumber is an integer between 1 (default) and 6 ''' from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE, APXXXX_ERROR_ARGUMENT_VALUE from PyApex.Errors import ApexError from random import random if not isinstance(Scale, str): raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "Scale") sys.exit() if not isinstance(TraceNumber, (int, float)): raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "TraceNumber") sys.exit() if TraceNumber <= 0 or TraceNumber > 6: raise ApexError(APXXXX_ERROR_ARGUMENT_VALUE, "TraceNumber") sys.exit() NPoints = self.GetNPoints() if not self.__Simulation: YData = [] XData = [] if Scale.lower() == "lin": Command = "OSAFSDATAL" + str(int(TraceNumber)) + "\n" else: Command = "OSAFSDATAD" + str(int(TraceNumber)) + "\n" Send(self.__Connexion, Command) YStr = Receive(self.__Connexion, 20 * NPoints)[:-1] print(YStr) YStr = YStr.split(" ") print(YStr) for s in YStr: try: YData.append(float(s)) except: YData.append(0.0) Command = "OSAFSDATAWL" + str(int(TraceNumber)) + "\n" Send(self.__Connexion, Command) XStr = Receive(self.__Connexion, 20 * NPoints)[:-1] print(XStr) XStr = XStr.split(" ") print(XStr) for s in XStr: try: XData.append(float(s)) except: XData.append(0.0) else: YData = [] XData = [] DeltaX = (self.__StopWavelength - self.__StartWavelength) / NPoints for i in range(0, NPoints): if Scale.lower() == "lin": YData.append(10.0 * random()) else: YData.append(60.0 * random() - 50.0) XData.append(self.__StartWavelength + i * DeltaX) return [YData, XData]