Пример #1
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])
Пример #2
0
    def GetEEPromData(self, BytesNumber):
        '''
        Get Data from the EEPROM of AB3380
        BytesNumber is the number of bytes to read from the EEProm
        Returns an array of the data bytes
        '''
        from PyApex.Constantes import AB3380_VR_GET_EEPROM_PARAMETERS, ABXXXX_EP0_READ_ERROR
        from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE
        from PyApex.Errors import ApexError
        from sys import exit

        if not isinstance(BytesNumber, int):
            raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "BytesNumber")
            exit()

        if self.Simulation:
            return -1
        else:
            Data = self.Device.ctrl_transfer(0xC0,
                                             AB3380_VR_GET_EEPROM_PARAMETERS,
                                             BytesNumber, 0, BytesNumber)
            try:
                len(Data)
            except:
                raise ApexError(ABXXXX_EP0_READ_ERROR,
                                AB3380_VR_GET_EEPROM_PARAMETERS)
                return -1
            else:
                return Data
Пример #3
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
Пример #4
0
 def __SetVoltage(self, Voltage, Filter=1):
     '''
     Calibration use only
     Set Voltage of the FIL equipment (DAC binary value)
     Voltage is expressed in binary value (between 0 and 65535)
     Filter is the number of the filter 1 (default) or 2
     '''
     from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE, APXXXX_ERROR_ARGUMENT_VALUE
     from PyApex.Errors import ApexError
     
     if not isinstance(Voltage, (int, float)):
         raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "Voltage")
         sys.exit()
     
     if not isinstance(Filter, (int)):
         raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "Filter")
         sys.exit()
     
     if(Voltage < 0 or Voltage > 65535):
         raise ApexError(APXXXX_ERROR_ARGUMENT_VALUE, "Voltage")
         sys.exit()
     
     if(Filter not in [1, 2]):
         raise ApexError(APXXXX_ERROR_ARGUMENT_VALUE, "Filter")
         sys.exit()
         
     if not self.__Simulation:
         Command = "FLT[" + str(self.__SlotNumber).zfill(2) + "]:SETV" + \
                   str(Filter) + str(Voltage) + "\n"
         Send(self.__Connexion, Command)
Пример #5
0
    def LockTrace(self, TraceNumber, Lock):
        '''
        Lock or unlock a trace
        TraceNumber is an integer between 1 and 6
        Lock is a boolean:
            - True: the trace TraceNumber is locked
            - False: the trace TraceNumber is unlocked
        '''
        from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE, APXXXX_ERROR_ARGUMENT_VALUE, APXXXX_ERROR_BAD_FILENAME
        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 Lock:
            Lock = True
        else:
            Lock = False

        if not self.__Simulation:
            if Lock:
                Command = "SPTRLOCK" + str(TraceNumber) + "\n"
            else:
                Command = "SPTRUNLOCK" + str(TraceNumber) + "\n"
            Send(self.__Connexion, Command)
Пример #6
0
    def SetEEPromData(self, Data):
        '''
        Set Data into the EEPROM of AB3380
        Data is a bytes object to write into the EEProm
        '''
        from PyApex.Constantes import AB3380_VR_SET_EEPROM_PARAMETERS, ABXXXX_EP0_WRITE_ERROR
        from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE
        from PyApex.Errors import ApexError
        from sys import exit

        if not isinstance(Data, bytes):
            raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "Data")
            exit()

        if self.Simulation:
            return True
        else:
            self.Device.ctrl_transfer(0x40, AB3380_VR_SET_EEPROM_PARAMETERS,
                                      len(Data), 0, Data)
            try:
                len(Data)
            except:
                raise ApexError(ABXXXX_EP0_WRITE_ERROR,
                                AB3380_VR_SET_EEPROM_PARAMETERS)
                return False
            else:
                return True
Пример #7
0
    def SetFrequency(self, Frequency, ChNumber=1):
        '''
        Set frequency of the channel ChNumber of the PWM equipment
        Frequency is expressed in GHz
        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 VACCUM_LIGHT_SPEED, AP1000_PWM_WLMAX
        from PyApex.Errors import ApexError

        try:
            Frequency = float(Frequency)
        except:
            self.__Connexion.close()
            raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "Frequency")
        else:
            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 Frequency > 0:
                    self.SetWavelength(VACCUM_LIGHT_SPEED / Frequency,
                                       ChNumber)
                else:
                    print("PyApex Warning. PWM Frequency is set to its minimum value: " + \
                          str(AP1000_PWM_WLMAX / VACCUM_LIGHT_SPEED) + " GHz !")
                    self.SetWavelength(AP1000_PWM_WLMAX, ChNumber)
Пример #8
0
    def SetScaleYUnit(self, ScaleYUnit=0):
        '''
        Defines the unit of the Y-Axis
        ScaleXUnit can be a string or an integer
        If ScaleYUnit is :
            - "lin" or 0, Y-Axis unit is in mW (default)
            - "log" or 1, Y-Axis unit is in dBm or dBm
        '''
        from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE, APXXXX_ERROR_ARGUMENT_VALUE
        from PyApex.Errors import ApexError

        if isinstance(ScaleYUnit, str):
            if ScaleYUnit.lower() == "log":
                ScaleYUnit = 1
            else:
                ScaleYUnit = 0

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

        if not ScaleYUnit in self.__ValidScaleUnits:
            raise ApexError(APXXXX_ERROR_ARGUMENT_VALUE, "ScaleYUnit")
            sys.exit()

        if not self.__Simulation:
            Command = "SPLINSC" + str(ScaleYUnit) + "\n"
            Send(self.__Connexion, Command)

        self.__ScaleYUnit = ScaleYUnit
Пример #9
0
    def FilterRun(self, Type="single"):
        '''
        Run a sweep with the optical filter
        If Type is
            - "single" or 1, a single measurement is running (default)
            - "repeat" or 2, a repeat measurement is running
        '''
        from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE
        from PyApex.Errors import ApexError

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

        if isinstance(Type, string):
            if Type.lower() == "repeat":
                Type = 2
            else:
                Type = 1
        elif isinstance(Type, int):
            if Type == 2:
                Type = 2
            else:
                Type = 1
        else:
            raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "Type")
            sys.exit()

        if not self.__Simulation:
            Command = "FILRUN" + str(Type) + "\n"
            Send(self.__Connexion, Command)
Пример #10
0
    def SetFilterMode(self, Mode="single"):
        '''
        Sets the filter mode
        Mode can be an integer or a string:
            Mode = 1 or "single" : Only 1 filter is used (default)
            Mode = 2 or "dual" : 2 cascaded filters are used
        '''
        from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE
        from PyApex.Errors import ApexError

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

        if isinstance(Mode, string):
            if Mode.lower() == "dual":
                Mode = 2
            else:
                Mode = 1
        elif isinstance(Mode, int):
            if Mode == 2:
                Mode = 2
            else:
                Mode = 1
        else:
            raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "Mode")
            sys.exit()

        if not self.__Simulation:
            Command = "FILMODE" + str(Mode) + "\n"
            Send(self.__Connexion, Command)
Пример #11
0
    def Open(self, Handle=0):
        '''
        Opens a connexion with an AB3380 equipment.
        This method is called by the constructor of AB3380 class if only 1 board is present
        '''
        from PyApex.Constantes import ABXXXX_ERROR_BAD_HANDLE
        from PyApex.Errors import ApexError
        from sys import exit

        if self.Simulation:
            print("Connected successfully to the equipment")
        else:
            try:
                Devices = self.Find()
                if len(Devices) == 0:
                    raise ApexError(ABXXXX_NO_EQUIPMENT_FOUND, "AB3380")
                    exit()
                elif len(Devices) <= Handle:
                    raise ApexError(ABXXXX_ERROR_BAD_HANDLE, Handle)
                    exit()

                self.Device = Devices[Handle]
                self.Device.set_configuration()
                print("Connected successfully to the equipment")
                self.EEPromData2Parameters()
            except:
                print("Cannot connect to the equipment")
Пример #12
0
    def SetSOACurrent(self, Current):
        '''
        !!! FOR TLS CALIBRATION ONLY !!!
        Set the SOA current. 'Current' is a 16-bits binary value 
        '''
        from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE, APXXXX_ERROR_ARGUMENT_VALUE
        from PyApex.Constantes import AP1000_TLS_SOAMIN, AP1000_TLS_SOAMAX
        from PyApex.Errors import ApexError

        if not isinstance(Current, (float, int)):
            self.Off()
            self.__Connexion.close()
            raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "Current")

        if Current < AP1000_TLS_SOAMIN or Current > AP1000_TLS_SOAMAX:
            self.Off()
            self.__Connexion.close()
            raise ApexError(APXXXX_ERROR_ARGUMENT_VALUE, "Current")

        if not self.__Simulation:
            Command = "TLS[" + str(self.__SlotNumber).zfill(
                2) + "]:SETSOAVALUE" + str(Current) + "\n"
            Send(self.__Connexion, Command)

        self.__SOACurrent = Current
Пример #13
0
    def SlotSN(self, SlotNumber, Force=False):
        '''
        Return the Serial Number (integer) of the module in the slot 'SlotNumber'
        If Force is True, the function return a S/N even if slot isn't used 
        '''
        from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE, APXXXX_ERROR_ARGUMENT_VALUE, AP1000_ERROR_SLOT_NOT_DEFINED
        from PyApex.Constantes import AP1000_SLOT_MIN, AP1000_SLOT_MAX
        from PyApex.Constantes import SimuAP1000_SlotID
        from PyApex.Errors import ApexError
        import re

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

        if self.__Simulation:
            SN = SimuAP1000_SlotID
        else:
            SN = self.SlotID(SlotNumber, Force=Force)

        try:
            SN = SN.lower().split("/")[2].split("-")
            SN = SN[len(SN) - 1]
            SN = int(re.findall("\d+", SN)[0])
            return int(SN)
        except:
            self.Connexion.close()
            raise ApexError(AP1000_ERROR_SLOT_NOT_DEFINED, SlotNumber)
Пример #14
0
    def SlotType(self, SlotNumber):
        '''
        Return a string describing the module in the slot 'SlotNumber'
        '''
        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 AP1000_ERROR_SLOT_NOT_DEFINED, SimuAP1000_SlotID, Modules
        from PyApex.Errors import ApexError
        from random import sample
        import re

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

        if self.__Simulation:
            ID = sample(list(Modules), 1)
            return Modules[ID[0]]
        else:
            if self.SlotUsed(SlotNumber):
                ID = self.SlotID(SlotNumber)
            else:
                return "Slot not used"

        try:
            ID = ID.lower().split("/")[1].split("-")[0]
            ID = int(re.findall("\d+", ID)[0])
            return Modules[ID]
        except:
            self.Connexion.close()
            raise ApexError(AP1000_ERROR_SLOT_NOT_DEFINED, SlotNumber)
Пример #15
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]
Пример #16
0
    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
Пример #17
0
def recvall(Connexion, ByteNumber):
    # # Helper function to recv n bytes or return None if EOF is hit
    # data = bytearray()
    # while len(data) < n:
    #     packet = Connexion.recv(n - len(data))
    #     if not packet:
    #         return None
    #     data.extend(packet)
    # return data

    from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE, APXXXX_ERROR_COMMUNICATION
    from PyApex.Errors import ApexError
    # from sys import exit
    from socket import timeout

    if not isinstance(ByteNumber, int):
        Connexion.close()
        raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "ByteNumber")
    try:
        # Helper function to recv n bytes or return None if EOF is hit
        data = bytearray()
        while len(data) < ByteNumber:
            packet = Connexion.recv(ByteNumber - len(data))
            if not packet:
                return None
            data.extend(packet)
    except timeout:
        Connexion.close()
        raise ApexError(APXXXX_ERROR_COMMUNICATION, Connexion.getsockname()[0])
    else:
        return data
Пример #18
0
 def __SetSwitch(self, Value, Filter=1):
     '''
     Calibration use only
     Set connection of the switch in the FIL equipment
     Value is a binary value (True or False)
     Filter is the number of the filter 1 (default) or 2
     '''
     from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE, APXXXX_ERROR_ARGUMENT_VALUE
     from PyApex.Errors import ApexError
     
     if not isinstance(Value, bool):
         raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "Value")
         sys.exit()
     
     if not isinstance(Filter, (int)):
         raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "Filter")
         sys.exit()
     
     if(Filter not in [1, 2]):
         raise ApexError(APXXXX_ERROR_ARGUMENT_VALUE, "Filter")
         sys.exit()
         
     if not self.__Simulation:
         Command = "FLT[" + str(self.__SlotNumber).zfill(2) + "]:SWITCH" + \
                   str(Filter) + str(int(Value)) + "\n"
         Send(self.__Connexion, Command)
Пример #19
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]
Пример #20
0
def Send(Connexion, Command):
    from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE, APXXXX_ERROR_BADCOMMAND
    from PyApex.Errors import ApexError
    from sys import exit
    from socket import timeout

    if not isinstance(Command, str):
        Connexion.close()
        raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "Command")
    try:
        Connexion.send(Command.encode('utf-8'))
    except timeout:
        Connexion.close()
        raise ApexError(APXXXX_ERROR_BADCOMMAND, Command)
Пример #21
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
Пример #22
0
    def AutoMeasure(self, TraceNumber=1, NbAverage=1):
        '''
        Auto measurement which performs a single and looks for the maximum peak
        If a peak is detected, this method selects the spectral range and modify the span
        TraceNumber is an integer between 1 (default) and 6
        NbAverage is the number of average to perform after the span selection (no average by default)
        '''
        from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE, APXXXX_ERROR_ARGUMENT_VALUE
        from PyApex.Constantes import AP2XXX_WLMIN, AP2XXX_WLMAX
        from PyApex.Errors import ApexError

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

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

        if int(NbAverage) < 1:
            NbAverage = 1

        if not TraceNumber in self.__Validtracenumbers:
            raise ApexError(APXXXX_ERROR_ARGUMENT_VALUE, "TraceNumber")
            sys.exit()

        self.DeleteAll()
        self.SetStartWavelength(AP2XXX_WLMIN)
        self.SetStopWavelength(AP2XXX_WLMAX)
        self.Run()

        PeakValue = self.FindPeak(TraceNumber, ThresholdValue=20.0, Find="Max")

        if PeakValue != 0.0:
            if self.ScaleXUnit == 0:
                self.SetSpan(125.0)
            else:
                self.SetSpan(1.0)
            self.SetCenter(PeakValue)

            self.DeleteAll()
            self.DelAllMarkers(TraceNumber)

            if int(NbAverage) > 1:
                self.ActivateAverageMode()
            for i in range(NbAverage):
                self.Run()
            if int(NbAverage) > 1:
                self.DesactivateAverageMode()
Пример #23
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
Пример #24
0
    def SetFrequency(self, Frequency):
        '''
        Set frequency of the DFB equipment
        Frequency is expressed in GHz
        '''
        from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE, APXXXX_ERROR_ARGUMENT_VALUE
        from PyApex.Constantes import VACCUM_LIGHT_SPEED, AP1000_DFB_FRMIN, AP1000_DFB_FRMAX
        from PyApex.Errors import ApexError

        try:
            Frequency = float(Frequency)
        except:
            self.Off()
            self.__Connexion.close()
            raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "Frequency")
        else:
            if Frequency < AP1000_DFB_FRMIN[self.__Type]:
                print("PyApex Warning. DFB Frequency is set to its minimum value: " + \
                      str(AP1000_DFB_FRMIN[self.__Type]) + " nm !")
                Frequency = AP1000_DFB_FRMIN[self.__Type]
            if Frequency > AP1000_DFB_FRMAX[self.__Type]:
                print("PyApex Warning. DFB Frequency is set to its maximum value: " + \
                      str(AP1000_DFB_FRMAX[self.__Type]) + " nm !")
                Frequency = AP1000_DFB_FRMAX[self.__Type]

            self.SetWavelength(VACCUM_LIGHT_SPEED / Frequency)
Пример #25
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
Пример #26
0
    def SetAverageTime(self, AvgTime):
        '''
        Set the average time of the PWM equipment
        AvgTime is expressed in ms
        '''
        from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE, APXXXX_ERROR_ARGUMENT_VALUE
        from PyApex.Constantes import AP1000_PWM_AVGMIN, AP1000_PWM_AVGMAX
        from PyApex.Errors import ApexError

        try:
            AvgTime = float(AvgTime)
        except:
            self.__Connexion.close()
            raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "AvgTime")
        else:
            if AvgTime < AP1000_PWM_AVGMIN:
                print("PyApex Warning. PWM Average time is set to its minimum value: " + \
                      str(AP1000_PWM_AVGMIN) + " ms !")
                AvgTime = AP1000_PWM_AVGMIN
            if AvgTime > AP1000_PWM_AVGMAX:
                print("PyApex Warning. PWM Average time is set to its maximum value: " + \
                      str(AP1000_PWM_AVGMAX) + " ms !")
                AvgTime = AP1000_PWM_AVGMAX

            if not self.__Simulation:
                Command = "POW[" + str(self.__SlotNumber).zfill(2) + "]:SETAVERAGE" + \
                          str(AvgTime) + "\n"
                Send(self.__Connexion, Command)

            self.__AvgTime = AvgTime
Пример #27
0
def Receive(Connexion, ByteNumber=1024):
    from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE, APXXXX_ERROR_COMMUNICATION
    from PyApex.Errors import ApexError
    from sys import exit
    from socket import timeout

    if not isinstance(ByteNumber, int):
        Connexion.close()
        raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "ByteNumber")
    try:
        data = Connexion.recv(ByteNumber)
    except timeout:
        Connexion.close()
        raise ApexError(APXXXX_ERROR_COMMUNICATION, Connexion.getsockname()[0])
    else:
        return data.decode('utf-8')
Пример #28
0
 def SetPower(self, Power):
     '''
     Set output power of the TLS equipment
     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 AP1000_TLS_POWMIN, AP1000_TLS_POWMAX
     from PyApex.Errors import ApexError
     
     try:
         Power = float(Power)
     except:
         self.Off()
         self.__Connexion.close()
         raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "Power")
     else:
         Power = self.__ConvertForWriting(Power)
         if Power < AP1000_TLS_POWMIN[self.__Type]:
             print("PyApex Warning. TLS Power is set to its minimum value: " + \
                   str(AP1000_TLS_POWMIN[self.__Type]) + " dBm !")
             Power = AP1000_TLS_POWMIN[self.__Type]
         elif Power > AP1000_TLS_POWMAX[self.__Type]:
             print("PyApex Warning. TLS Power is set to its maximum value: " + \
                   str(AP1000_TLS_POWMIN[self.__Type]) + " dBm !")
             Power = AP1000_TLS_POWMAX[self.__Type]
             
         if not self.__Simulation:
             Command = "TLS[" + str(self.__SlotNumber).zfill(2) + "]:TPDB" + \
                       ("%.1f" % Power) + "\n"
             Send(self.__Connexion, Command)
         
         self.__Power = Power
Пример #29
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)
Пример #30
0
 def SetWavelength(self, Wavelength):
     '''
     Set wavelength of the TLS equipment
     Wavelength is expressed in nm
     '''
     from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE, APXXXX_ERROR_ARGUMENT_VALUE
     from PyApex.Constantes import AP1000_TLS_WLMIN, AP1000_TLS_WLMAX
     from PyApex.Errors import ApexError
     
     try:
         Wavelength = float(Wavelength)
     except:
         self.Off()
         self.__Connexion.close()
         raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "Wavelength")
     else:
         if Wavelength < AP1000_TLS_WLMIN[self.__Type]:
             print("PyApex Warning. TLS Wavelength is set to its minimum value: " + \
                   str(AP1000_TLS_WLMIN[self.__Type]) + " nm !")
             Wavelength = AP1000_TLS_WLMIN[self.__Type]
         if Wavelength > AP1000_TLS_WLMAX[self.__Type]:
             print("PyApex Warning. TLS Wavelength is set to its maximum value: " + \
                   str(AP1000_TLS_WLMAX[self.__Type]) + " nm !")
             Wavelength = AP1000_TLS_WLMAX[self.__Type]
         
         if not self.__Simulation:
             Command = "TLS[" + str(self.__SlotNumber).zfill(2) + "]:TWL" + \
                       ("%4.3f" % Wavelength).zfill(8) + "\n"
             Send(self.__Connexion, Command)
         
         self.__Wavelength = Wavelength