예제 #1
0
    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)
예제 #2
0
    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)
예제 #3
0
 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
예제 #4
0
 def GetPath(self):
     '''
     Get path of the OSW equipment.
     Returns an integer
     For 1X2 and 2X2 OSW, returns:
         - 0 for straight
         - 1 for crossed
     For 1X4 OSW, returns:
         - 1, 2, 3 or 4
     For 1X8 OSW, Path can be:
         - 1, 2, 3, 4, 5, 6, 7 or 8
     '''
     from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE, APXXXX_ERROR_ARGUMENT_VALUE
     from PyApex.Errors import ApexError
     
     if self.__Simulation:
         Path = str(self.__Path) + "\n"
     else:
         if self.__Type == 0:
             Command = "SWI[" + str(self.__SlotNumber).zfill(2) + "]:CONF?\n"
             Send(self.__Connexion, Command)
             Path = Receive(self.__Connexion)
         elif self.__Type == 1:
             Command = "SWx4x8[" + str(self.__SlotNumber).zfill(2) + "]:GETx4?\n"
             Send(self.__Connexion, Command)
             Path = Receive(self.__Connexion)[3:]
         elif self.__Type == 2:
             Command = "SWx4x8[" + str(self.__SlotNumber).zfill(2) + "]:GETx8?\n"
             Send(self.__Connexion, Command)
             Path = Receive(self.__Connexion)[3:]
     
     self.__Path = int(Path[:-1])
     
     return self.__Path
예제 #5
0
    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)
예제 #6
0
    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]
예제 #7
0
    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]
예제 #8
0
 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)
예제 #9
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
예제 #10
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
예제 #11
0
    def SlotID(self, SlotNumber, Force=False):
        '''
        Return a string ID of the module selected by 'SlotNumber'
        If Force is True, the function return an ID even if slot isn't used
        '''
        from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE, APXXXX_ERROR_ARGUMENT_VALUE
        from PyApex.Constantes import AP1000_SLOT_MIN, AP1000_SLOT_MAX
        from PyApex.Constantes import SimuAP1000_SlotID
        from PyApex.Errors import ApexError

        if not isinstance(SlotNumber, int):
            self.Connexion.close()
            raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "SlotNumber")
        if SlotNumber < AP1000_SLOT_MIN or SlotNumber > AP1000_SLOT_MAX:
            self.Connexion.close()
            raise ApexError(APXXXX_ERROR_ARGUMENT_VALUE, "SlotNumber")

        if self.__Simulation:
            ID = SimuAP1000_SlotID
        else:
            if Force:
                SlotUsed = True
            else:
                SlotUsed = self.SlotUsed(SlotNumber)
            if SlotUsed:
                Command = "SLT[" + str(SlotNumber).zfill(2) + "]:IDN?\n"
                Error = Send(self.Connexion, Command)
                ID = Receive(self.Connexion)
            else:
                return "Slot not used"

        return ID[:-1]
예제 #12
0
    def GetRawValues(self):
        '''
        !!! FOR CALIBRATION ONLY !!!
        Get the raw values of the 4 detectors of the POL equipment
        '''
        from random import randint

        if self.__Simulation:
            Raw = []
            for i in range(4):
                Raw.append(randint(0, 16384))
        else:
            Command = "POL[" + str(self.__SlotNumber).zfill(2) + "]:RAW4?\n"
            Send(self.__Connexion, Command)
            VALstr = Receive(self.__Connexion)
            VALstr = VALstr[:-1].split(" ")

            Raw = []
            for v in VALstr:
                try:
                    Raw.append(int(v))
                except:
                    Raw.append(float("NAN"))

        return Raw
예제 #13
0
    def GetSOP(self):
        '''
        Get a measured SOP by the POL equipment
        The returned SOP is expressed in nominal values and separated by space
        '''
        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 self.__Simulation:
            SOP = []
            for i in range(4):
                SOP.append(random() * 2.0 - 1.0)
        else:
            Command = "POL[" + str(self.__SlotNumber).zfill(2) + "]:SOP?\n"
            Send(self.__Connexion, Command)
            VALstr = Receive(self.__Connexion)
            VALstr = VALstr[:-1].split(" ")

            SOP = []
            for v in VALstr:
                try:
                    SOP.append(float(v))
                except:
                    SOP.append(float("NAN"))

        return SOP
예제 #14
0
    def GetPower(self):
        '''
        Get the total power of the POL equipment
        The return power is expressed in the unit defined by the GetUnit() method
        '''
        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 self.__Simulation:
            Power = random() * 70.0 - 60.0
            if self.__Unit.lower() == "mw":
                Power = 10.0**(Power / 10.0)
        else:
            if self.__Unit.lower() == "dbm":
                Command = "POL[" + str(self.__SlotNumber).zfill(2) + "]:DBM?\n"
            elif self.__Unit.lower() == "mw":
                Command = "POL[" + str(self.__SlotNumber).zfill(2) + "]:MW?\n"
            else:
                self.__Connexion.close()
                raise ApexError(APXXXX_ERROR_VARIABLE_NOT_DEFINED,
                                "self.__Unit")

            Send(self.__Connexion, Command)
            Power = Receive(self.__Connexion)

            try:
                Power = float(Power[:-1])
            except:
                Power = float("NAN")

        return Power
예제 #15
0
파일: osafs.py 프로젝트: rujutavb/PyApex
    def GetNPoints(self, TraceNumber=1):
        '''
        Get the number of points for the specified trace on the OSA Fast-Sweep
        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 randint

        if not isinstance(TraceNumber, (int)):
            raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "TraceNumber")
            sys.exit()

        if TraceNumber < 0 or TraceNumber > 6:
            raise ApexError(APXXXX_ERROR_ARGUMENT_VALUE, "TraceNumber")
            sys.exit()

        if self.__Simulation:
            NPoints = randint(400, 600)
        else:
            Command = "OSAFSPOINTS" + str(int(TraceNumber)) + "\n"
            Send(self.__Connexion, Command)
            try:
                NPoints = int(Receive(self.__Connexion)[:-1])
            except:
                NPoints = 0

        return NPoints
예제 #16
0
 def GetPolarimeterPath(self):
     '''
     Gets the polarimeter path
     The returned path is a string:
         - "full" if the polarimeter input is used (no optical filter),
         - "filtered" if the OSA input is used (a 170 pm optical filter is used)
         - "error" if it's not a defined path
     '''
     
     PathString = ""
     if not self.__Simulation:
         Command = "POLPATH?\n"
         Send(self.__Connexion, Command)
         Str = Receive(self.__Connexion, 64)[:-1]
         
         try:
             if int(Str) == 1:
                 PathString = "filtered"
             elif int(Str) == 0:
                 PathString = "full"
         except:
             PathString = "error"
     else:
         PathString = "full"
     
     return PathString
예제 #17
0
    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)

        return float(Power[:-1])
예제 #18
0
    def GetAttenuation(self, ChNumber=1):
        '''
        Get attenuation of the ATT equipment
        The return attenuation is expressed in the unit defined by the GetUnit() method
        ChNumber is the channel number : 1 (default) or 2
        '''
        from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE, APXXXX_ERROR_ARGUMENT_VALUE
        from PyApex.Constantes import AP1000_ATT_CHNUMBER, SimuATT_Attenuation
        from PyApex.Errors import ApexError

        try:
            ChNumber = int(ChNumber)
        except:
            self.__Connexion.close()
            raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "ChNumber")
        else:

            if ChNumber > AP1000_ATT_CHNUMBER:
                ChNumber = AP1000_ATT_CHNUMBER
            if ChNumber < 1:
                ChNumber = 1

            if not self.__Simulation:
                Command = "ATT[" + str(self.__SlotNumber).zfill(2) + "]:DB[" + \
                          str(ChNumber-1) + "]?\n"
                Send(self.__Connexion, Command)
                self.__Attenuation = self.__ConvertForReading(
                    float(Receive(self.__Connexion)[:-1]))

            return self.__Attenuation
예제 #19
0
파일: osafs.py 프로젝트: rujutavb/PyApex
    def GetOSAMode(self, Type='d'):
        '''
        Return the OSA Fast-Sweep mode (Fast or High-Sensitivity)
        if Type = 'd' (default), return a digit :
            - 1 for Fast
            - 2 for Sensitive
        if Type = 's', return a string :
            - "Fast" for Fast
            - "Sensitive" for High-Sensitivity
        '''
        from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE
        from PyApex.Errors import ApexError

        if not isintance(Type, (str)):
            raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "Type")
            sys.exit()

        if not self.__Simulation:
            Command = "OSAFSMODE?\n"
            Send(self.__Connexion, Command)
            self.__Mode = int(Receive(self.__Connexion)[:-1])

        if str(Type).lower() == 's':
            if self.__Mode == 1:
                return "Fast"
            elif self.__Mode == 2:
                return "Sensitive"
            else:
                return "Unknown Mode"
        else:
            return self.__Mode
예제 #20
0
    def GetPowerValues(self):
        '''
        !!! FOR CALIBRATION ONLY !!!
        Get the Power values (in dBm) of the 4 detectors of the POL equipment
        '''
        from random import random

        if self.__Simulation:
            Pow = []
            for i in range(4):
                Pow.append(random() * 70.0 - 60.0)
        else:
            Command = "POL[" + str(self.__SlotNumber).zfill(2) + "]:POW4?\n"
            Send(self.__Connexion, Command)
            VALstr = Receive(self.__Connexion)
            VALstr = VALstr[:-1].split(" ")

            Pow = []
            for v in VALstr:
                try:
                    Pow.append(float(v))
                except:
                    Pow.append(float("NAN"))

        return Pow
예제 #21
0
    def Run(self, Type="single"):
        '''
        Runs a measurement and returns the trace of the measurement (between 1 and 6)
        If Type is
            - "auto" or 0, an auto-measurement is running
            - "single" or 1, a single measurement is running (default)
            - "repeat" or 2, a repeat measurement is running
        '''

        if not self.__Simulation:
            if isinstance(Type, str):
                if Type.lower() == "auto":
                    Command = "SPSWP0\n"
                elif Type.lower() == "repeat":
                    Command = "SPSWP2\n"
                else:
                    Command = "SPSWP1\n"
            else:
                if Type == 0:
                    Command = "SPSWP0\n"
                elif Type == 2:
                    Command = "SPSWP2\n"
                else:
                    Command = "SPSWP1\n"

            Send(self.__Connexion, Command)
            try:
                trace = int(Receive(self.__Connexion))
            except:
                trace = 0
        else:
            trace = 1

        return trace
예제 #22
0
    def SlotUsed(self, SlotNumber):
        '''
        Return a boolean indicated if slot 'SlotNumber' is used by AP1000 equipment
            - if return True : Slot is used by a module
            - if return False : Slot is not used
        '''
        from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE, APXXXX_ERROR_ARGUMENT_VALUE
        from PyApex.Constantes import AP1000_SLOT_MIN, AP1000_SLOT_MAX
        from PyApex.Constantes import SimuAP1000_SlotUsed
        from PyApex.Errors import ApexError

        if not isinstance(SlotNumber, int):
            self.Connexion.close()
            raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "SlotNumber")
        if SlotNumber < AP1000_SLOT_MIN or SlotNumber > AP1000_SLOT_MAX:
            self.Connexion.close()
            raise ApexError(APXXXX_ERROR_ARGUMENT_VALUE, "SlotNumber")

        if self.__Simulation:
            ID = SimuAP1000_SlotUsed
        else:
            Command = "SLT[" + str(SlotNumber).zfill(2) + "]:EMPTY?\n"
            Send(self.Connexion, Command)
            ID = Receive(self.Connexion, 10)

        if ID[:-1] == "0":
            return False
        elif ID[:-1] == "1":
            return True
예제 #23
0
    def GetWavelength(self, ChNumber=1):
        '''
        Get wavelength of the channel ChNumber of the PWM equipment
        The return wavelength is expressed in nm
        ChNumber is the channel number : 1 (default) or 2
        '''
        from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE, APXXXX_ERROR_ARGUMENT_VALUE
        from PyApex.Errors import ApexError

        try:
            ChNumber = int(ChNumber)
        except:
            self.__Connexion.close()
            raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "ChNumber")
        else:
            if ChNumber > len(self.__Channels):
                print("PyApex Warning. PWM Channel is set to 1 !")
                ChNumber = 1

            if not self.__Simulation:
                Command = "POW[" + str(slef.__SlotNumber).zfill(2) + "]:WAV[" + \
                          str(ChNumber) + "]?\n"
                Send(self.__Connexion, Command)
                self.__Wavelength = float(Receive(self.__Connexion)[:-1])

            return self.__Wavelength
예제 #24
0
    def GetMode(self):
        '''
        Gets the working mode of the EFA equipment
        '''

        Command = "AMP[" + str(self.__SlotNumber).zfill(2) + "]:MODE?\n"

        if not self.__Simulation:
            Send(self.__Connexion, Command)
            Mode = Receive(self.__Connexion)

        try:
            Mode = int(Mode)
            self.__Mode = Mode
        except:
            pass

        if self.__Mode == -1:
            return "off"
        elif self.__Mode == 0:
            return "manual"
        elif self.__Mode == 1:
            return "constant power"
        elif self.__Mode == 2:
            return "constant gain"
        else:
            return "unknown mode"
예제 #25
0
파일: __init__.py 프로젝트: rujutavb/PyApex
    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
예제 #26
0
 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
예제 #27
0
파일: __init__.py 프로젝트: rujutavb/PyApex
    def GetOpticalBand(self):
        '''
        Gets the actual optical band. The band can be:
            - O
            - C&L
        The optical band choice is only available for AP2X8X
        '''
        from random import randint

        if self.__Simulation:
            Bands = ["0", "C&L"]
            Band = Bands[randint(0, 1)]
        else:
            Send(self.Connexion, "CHBAND?\n")
            Band = Receive(self.Connexion)[:-1]
            Band = Band.replace("&&", "&")

        return Band
예제 #28
0
    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)
예제 #29
0
 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)
예제 #30
0
    def GetStepNum(self):
        '''
        Get the static wavelength of the TLS equipment
        The wavelength is expressed in nm
        '''
        if not self.__Simulation:
            Command = "TLSSTEPNUM?\n"
            Send(self.__Connexion, Command)
            StepNum = int(Receive(self.__Connexion)[:-1])

        return StepNum
예제 #31
0
    def GetNPoints(self):
        '''
        Get the number of points for the measurement
        '''

        if not self.__Simulation:
            Command = "SPNBPTSWP?\n"
            Send(self.__Connexion, Command)
            self.__NPoints = int(Receive(self.__Connexion)[:-1])

        return self.__NPoints
예제 #32
0
 def GetFrequencyLimits(self):
     '''
     Get the frequency limits (min and max) of the FIL equipment
     Returns the limits in GHz in a list [min, max]
     '''
     from PyApex.Constantes import AP1000_FIL_FRMIN, AP1000_FIL_FRMAX
     from PyApex.Errors import ApexError
     
     if self.__Simulation:
         FrequencyMin = AP1000_FIL_FRMIN
         FrequencyMax = AP1000_FIL_FRMAX
     else:
         Command = "FLT[" + str(self.__SlotNumber).zfill(2) + "]:FRMIN?\n"
         Send(self.__Connexion, Command)
         FrequencyMin = float(Receive(self.__Connexion)[:-1])
         Command = "FLT[" + str(self.__SlotNumber).zfill(2) + "]:FRMAX?\n"
         Send(self.__Connexion, Command)
         FrequencyMax = float(Receive(self.__Connexion)[:-1])
     
     return [FrequencyMin, FrequencyMax]
예제 #33
0
 def GetWavelngthLimits(self):
     '''
     Get the wavelength limits (min and max) of the FIL equipment
     Returns the limits in nm in a list [min, max]
     '''
     from PyApex.Constantes import AP1000_FIL_WLMIN, AP1000_FIL_WLMAX
     from PyApex.Errors import ApexError
     
     if self.__Simulation:
         WavelengthMin = AP1000_FIL_WLMIN
         WavelengthMax = AP1000_FIL_WLMAX
     else:
         Command = "FLT[" + str(self.__SlotNumber).zfill(2) + "]:WLMIN?\n"
         Send(self.__Connexion, Command)
         WavelengthMin = float(Receive(self.__Connexion)[:-1])
         Command = "FLT[" + str(self.__SlotNumber).zfill(2) + "]:WLMAX?\n"
         Send(self.__Connexion, Command)
         WavelengthMax = float(Receive(self.__Connexion)[:-1])
     
     return [WavelengthMin, WavelengthMax]
예제 #34
0
    def GetStepDelay(self):
        '''
        Get the step delay of the TLS equipment
        The step delay is expressed in s
        '''
        if not self.__Simulation:
            Command = "TLSSTEPDELAY?\n"
            Send(self.__Connexion, Command)
            StepDelay = float(Receive(self.__Connexion)[:-1])

        return StepDelay
예제 #35
0
    def GetWLUnit(self):
        '''
        Get WL Unit of the TLS equipment
        The Wavelength Unit is expressed in "nm" or "GHz"
        '''
        if not self.__Simulation:
            Command = "TLSWLUNT?\n"
            Send(self.__Connexion, Command)
            self.__WLUnit = (Receive(self.__Connexion)[:-1])

        return self.__WLUnit
예제 #36
0
 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
예제 #37
0
 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
예제 #38
0
 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
예제 #39
0
 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:]]