Ejemplo n.º 1
0
    def SetDiodeTemp(self, DiodeNumber, Temperature, SweepSpeed, SOAComp):
        '''
        !!! FOR TLS CALIBRATION ONLY !!!
        Select the laser diode 'DiodeNumber' (between 1 and 12)
        Set the temperature of the diode. 'Temperature' is a 16-bits binary value
        Set the temperature tuning speed
        Set the SOA compensation value
        '''
        from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE, APXXXX_ERROR_ARGUMENT_VALUE
        from PyApex.Constantes import AP1000_TLS_TMIN, AP1000_TLS_TMAX
        from PyApex.Errors import ApexError

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

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

        if DiodeNumber < 1 or DiodeNumber > 12:
            self.Off()
            self.__Connexion.close()
            raise ApexError(APXXXX_ERROR_ARGUMENT_VALUE, "DiodeNumber")

        if Temperature < AP1000_TLS_TMIN or Temperature > AP1000_TLS_TMAX:
            self.Off()
            self.__Connexion.close()
            raise ApexError(APXXXX_ERROR_ARGUMENT_VALUE, "Temperature")

        if not self.__Simulation:
            Command = "TLS[" + str(
                self.__SlotNumber).zfill(2) + "]:SETTARGETPARAM" + str(
                    DiodeNumber) + ";" + str(Temperature) + ";" + str(
                        SweepSpeed) + ";" + str(SOAComp) + "\n"
            Send(self.__Connexion, Command)

        self.__DiodeNumber = DiodeNumber
        self.__DiodeTemp = Temperature
        self.__SweepSpeed = SweepSpeed
        self.__SOAComp = SOAComp
Ejemplo n.º 2
0
 def GetPolarimeterWavelength(self):
     '''
     Gets the polarimeter wavelength
     The returned wavelength is expressed in nm
     '''
     
     if not self.__Simulation:
         Command = "POLWL?\n"
         Send(self.__Connexion, Command)
         Str = Receive(self.__Connexion, 64)[:-1]
         
         try:
             Wavelength = float(Str)
         except:
             Wavelength = 0.0
     else:
         Wavelength = 1550.0
     
     return Wavelength        
Ejemplo n.º 3
0
    def SetYResolution(self, Resolution):
        '''
        Set the Y-axis power per division value
        Resolution is expressed in the value of 'ScaleYUnit'
        '''
        from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE, APXXXX_ERROR_ARGUMENT_VALUE
        from PyApex.Constantes import AP2XXX_MINYRES, AP2XXX_MAXYRES
        from PyApex.Errors import ApexError

        if not isinstance(Resolution, (float, int)):
            raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "Resolution")
            sys.exit()
        if Resolution < AP2XXX_MINYRES or Resolution > AP2XXX_MAXYRES:
            raise ApexError(APXXXX_ERROR_ARGUMENT_VALUE, "Resolution")
            sys.exit()

        if not self.__Simulation:
            Command = "SPDIVY" + str(Resolution) + "\n"
            Send(self.__Connexion, Command)
Ejemplo n.º 4
0
    def SetStopWavelength(self, Wavelength):
        '''
        Set the stop wavelength of the measurement span
        Wavelength is expressed in nm
        '''
        from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE, APXXXX_ERROR_ARGUMENT_VALUE
        from PyApex.Errors import ApexError

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

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

        self.__StopWavelength = Wavelength
        self.__Span = self.__StopWavelength - self.__StartWavelength
        self.__Center = self.__StartWavelength + (self.__Span / 2)
Ejemplo n.º 5
0
    def SetOpticalBand(self, Band):
        '''
        Sets the optical band. The band can be:
        The available bands can be listed by the 'ListBands' command
        The optical band choice is only available for AP2X8X
        '''
        from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE

        if not isinstance(Band, (str)):
            raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "Band")

        ValidBands = self.ListBands()
        index = -1
        for vb in ValidBands:
            if Band.lower() == vb.lower():
                index = ValidBands.index(vb)

        if not self.__Simulation and index >= 0:
            Send(self.Connexion, "CHBAND" + str(index) + "\n")
Ejemplo n.º 6
0
    def SetCenter(self, Center):
        '''
        Set the wavelength measurement center
        Center is expressed in nm
        '''
        from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE, APXXXX_ERROR_ARGUMENT_VALUE
        from PyApex.Errors import ApexError

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

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

        self.__Center = Center
        self.__StopWavelength = self.__Center + (self.__Span / 2)
        self.__StartWavelength = self.__Center - (self.__Span / 2)
Ejemplo n.º 7
0
    def ChangeMode(self, Mode):
        '''
        Changes the screen mode of the AP2XXX equipment (Apex Start, O.S.A., Powermeter)
        Mode is an integer representing the index of the mode to display.
        By convention, the "APEX Start" mode is always 0 index. The index follows the
        list in the AP2XXX menu box.
        '''
        from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE

        TimeOut = self.Connexion.gettimeout()
        self.Connexion.settimeout(None)

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

        if not self.__Simulation:
            Send(self.Connexion, "CHMOD" + str(Mode) + "\n")

        self.Connexion.settimeout(TimeOut)
Ejemplo n.º 8
0
    def GetFilterWavelength(self):
        '''
        Gets the static wavelength of the optical filter
        the returned wavelength is expressed in nm
        '''
        from random import random

        if not self.__Simulation:
            Command = "FILWL?\n"
            Send(self.__Connexion, Command)
            Wavelength = Receive(self.__Connexion, 64)[:-1]
            try:
                Wavelength = float(Wavelength)
            except:
                pass
        else:
            Wavelength = 30.0 * random() + 1530.0

        return Wavelength
Ejemplo n.º 9
0
    def SetSpan(self, Span):
        '''
        Set the wavelength measurement span
        Span is expressed in nm
        '''
        from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE, APXXXX_ERROR_ARGUMENT_VALUE
        from PyApex.Errors import ApexError

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

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

        self.__Span = Span
        self.__StopWavelength = self.__Center + (self.__Span / 2)
        self.__StartWavelength = self.__Center - (self.__Span / 2)
Ejemplo n.º 10
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)
Ejemplo n.º 11
0
    def SetPower(self, Power):
        '''
        Set the power of the TLS equipment
        The power is expressed in the unit defined by the GetUnit() method
        '''
        from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE
        from PyApex.Errors import ApexError
        from math import log10 as log

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

        if self.__Unit.lower() == "mw":
            Power = 10.0 * log(Power)
        self.__Power = Power

        if not self.__Simulation:
            Command = "TLSPWR" + str("%.1f" % self.__Power) + "\n"
            Send(self.__Connexion, Command)
Ejemplo n.º 12
0
    def GetFilterOutput(self):
        '''
        Gets the state of the internal optical switch
        the returned state is a boolean:
            - State = False : the filter output is not enabled
            - State = True : the filter output is enabled
        '''

        if not self.__Simulation:
            Command = "FILOUTENABLE?\n"
            Send(self.__Connexion, Command)
            State = Receive(self.__Connexion, 64)[:-1]
            try:
                State = bool(int(State))
            except:
                pass
        else:
            State = True

        return State
Ejemplo n.º 13
0
    def Run(self, Type="single"):
        '''
        Run a single or repeat sweep in the OSA module
        Type is a string or an integer:
            - 1 or "single" : Run a single sweep (default)
            - 2 or "repeat" : Run a repeat sweep
        '''
        if isinstance(Type, str):
            if Type.lower() == "repeat":
                Type = 2
            else:
                Type = 1
        else:
            if Type not in [1, 2]:
                Type = 1

        if not self.__Simulation:
            Command = "OSA[" + str(self.__PowSlotNumber).zfill(2) + "]:SWEEP" + \
                      str(Type) + "\n"
            Send(self.__Connexion, Command)
Ejemplo n.º 14
0
    def GetTemperature(self):
        '''
        !!! FOR CALIBRATION ONLY !!!
        Get the temperature (in °C) of the POL equipment
        '''
        from random import random

        if self.__Simulation:
            Temp = random() * 40.0 + 10.0
        else:
            Command = "POL[" + str(self.__SlotNumber).zfill(2) + "]:TEMP?\n"
            Send(self.__Connexion, Command)
            Temp = Receive(self.__Connexion)[:-1]

            try:
                Temp = float(Temp)
            except:
                Temp = float("NAN")

        return Temp
Ejemplo n.º 15
0
    def DelAllMarkers(self, TraceNumber=1):
        '''
        Deletes all markers of a selected trace
        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

        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()

        Markers = []
        if not self.__Simulation:
            Command = "SPMKRDELAL" + str(TraceNumber) + "\n"
            Send(self.__Connexion, Command)
Ejemplo n.º 16
0
    def SetNPoints(self, NPoints):
        '''
        Set the number of points for the measurement
        '''
        from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE, APXXXX_ERROR_ARGUMENT_VALUE
        from PyApex.Constantes import AP2XXX_MINNPTS, AP2XXX_MAXNPTS
        from PyApex.Errors import ApexError

        if not isinstance(NPoints, int):
            raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "NPoints")
            sys.exit()
        if NPoints < AP2XXX_MINNPTS or NPoints > AP2XXX_MAXNPTS:
            raise ApexError(APXXXX_ERROR_ARGUMENT_VALUE, "NPoints")
            sys.exit()

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

        self.__NPoints = NPoints
Ejemplo n.º 17
0
    def SetFilterSlotNumber(self, Slot):
        '''
        Sets the slot number of the Filter used for the O.S.A. module
        Slot is an integer representing the slot number
        '''
        from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE
        from PyApex.Errors import ApexError

        try:
            Slot = int(Slot)
        except:
            self.__Connexion.close()
            raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "Slot")
        else:
            if not self.__Simulation:
                Command = "OSA[" + str(self.__PowSlotNumber).zfill(2) + "]:FILTER" + \
                          str(Slot) + "\n"
                Send(self.__Connexion, Command)

            self.__FilSlotNumber = Slot
Ejemplo n.º 18
0
    def SetNbPoints(self, NbPoints):
        '''
        Set the number of points of the OSA equipment
        NbPoints is an integer
        '''
        from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE
        from PyApex.Errors import ApexError

        try:
            NbPoints = int(NbPoints)
        except:
            self.__Connexion.close()
            raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "NbPoints")
        else:
            if not self.__Simulation:
                Command = "OSA[" + str(self.__PowSlotNumber).zfill(2) + "]:NBPTS" + \
                          str(NbPoints) + "\n"
                Send(self.__Connexion, Command)

            self.__NbPoints = NbPoints
Ejemplo n.º 19
0
    def SetStopWavelength(self, Wavelength):
        '''
        Set the stop wavelength of the OSA equipment
        Wavelength is expressed in nm
        '''
        from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE
        from PyApex.Errors import ApexError

        try:
            Wavelength = float(Wavelength)
        except:
            self.__Connexion.close()
            raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "Wavelength")
        else:
            if not self.__Simulation:
                Command = "OSA[" + str(self.__PowSlotNumber).zfill(2) + \
                          "]:STOPWL" + ("%4.3f" % Wavelength).zfill(8) + "\n"
                Send(self.__Connexion, Command)

            self.__StopWavelength = Wavelength
Ejemplo n.º 20
0
    def GetMode(self):
        '''
        Gets the actual mode of the AP2XXX equipment (Apex Start, O.S.A., Powermeter...)
        The returned mode is an integer representing the index of the displayed mode.
        The mode string can be defined by finding the element in the list returned by
        the function ListModes()
        '''
        from random import randint

        if self.__Simulation:
            Mode = randint(0, 6)
        else:
            Send(self.Connexion, "CHMOD?\n")
            Mode = Receive(self.Connexion)[:-1]
            try:
                Mode = int(Mode)
            except:
                Mode = 0

        return Mode
Ejemplo n.º 21
0
    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
Ejemplo n.º 22
0
 def GetPolarimeterTemp(self):
     '''
     Gets the polarimeter temperature in °C
     !!! FOR CALIBRATION ONLY !!!
     '''
     from random import random
     
     if not self.__Simulation:
         Command = "POLTEMP?\n"
         Send(self.__Connexion, Command)
         Str = Receive(self.__Connexion, 64)[:-1]
         
         try:
             Temperature = float(Str)
         except:
             Temperature = 0.0
     else:
         Temperature = 10.0 * random() + 20.0
     
     return Temperature
Ejemplo n.º 23
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
        In this function, the connection timeout is disabled and enabled after the
        execution of the function
        '''

        if self.__Simulation:
            trace = 1
        else:
            TimeOut = self.__Connexion.gettimeout()
            self.__Connexion.settimeout(None)

            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

            self.__Connexion.settimeout(TimeOut)

        return trace
Ejemplo n.º 24
0
    def SetWavelength(self, Wavelength, ChNumber=1):
        '''
        Set wavelength of the channel ChNumber of the PWM equipment
        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.Constantes import AP1000_PWM_WLMIN, AP1000_PWM_WLMAX
        from PyApex.Errors import ApexError

        try:
            Wavelength = float(Wavelength)
        except:
            self.__Connexion.close()
            raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "Wavelength")
        else:
            try:
                ChNumber = int(ChNumber)
            except:
                self.__Connexion.close()
                raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "ChNumber")
            else:
                if Wavelength < AP1000_PWM_WLMIN:
                    print("PyApex Warning. PWM Wavelength is set to its minimum value: " + \
                          str(AP1000_PWM_WLMIN) + " nm !")
                    Wavelength = AP1000_PWM_WLMIN
                if Wavelength > AP1000_PWM_WLMAX:
                    print("PyApex Warning. PWM Wavelength is set to its maximum value: " + \
                          str(AP1000_PWM_WLMAX) + " nm !")
                    Wavelength = AP1000_PWM_WLMAX
                if ChNumber > len(self.__Channels):
                    print("PyApex Warning. PWM Channel is set to 1 !")
                    ChNumber = 1

                if not self.__Simulation:
                    Command = "POW[" + str(self.__SlotNumber).zfill(2) + \
                              "]:SETWAVELENGTH[" + str(ChNumber) + "]" + \
                              ("%4.3f" % Wavelength).zfill(8) + "\n"
                    Send(self.__Connexion, Command)

                self.__Wavelength = Wavelength
Ejemplo n.º 25
0
    def GetPower(self):
        '''
        Get the power of the TLS equipment
        The returned 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 not self.__Simulation:
            Command = "TLSPWR?\n"
            Send(self.__Connexion, Command)
            Power = float(Receive(self.__Connexion)[:-1])

            if self.__Unit.lower() == "mw":
                Power = 10.0**(Power / 10.0)

            self.__Power = Power

        return self.__Power
Ejemplo n.º 26
0
 def SetSweepSpeed(self, SweepSpeed):
     '''
     Set the speed for a sweep
     SweepSpeed is expressed in nm/s
     '''
     from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE, APXXXX_ERROR_ARGUMENT_VALUE
     from PyApex.Constantes import AP1000_FIL_SPEEDMIN, AP1000_FIL_SPEEDMAX
     from PyApex.Errors import ApexError
     
     if not isinstance(SweepSpeed, (int, float)):
         raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "SweepSpeed")
         sys.exit()
     
     if(SweepSpeed < AP1000_FIL_SPEEDMIN or SweepSpeed > AP1000_FIL_SPEEDMAX):
         raise ApexError(APXXXX_ERROR_ARGUMENT_VALUE, "SweepSpeed")
         sys.exit()
         
     if not self.__Simulation:
         Command = "FLT[" + str(self.__SlotNumber).zfill(2) + "]:TSWES" + \
                   ("%.2f" % SweepSpeed) + "\n"
         Send(self.__Connexion, Command)
Ejemplo n.º 27
0
 def SetStopWavelength(self, Wavelength):
     '''
     Set the stop wavelength for a sweep
     Wavelength is expressed in nm
     '''
     from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE, APXXXX_ERROR_ARGUMENT_VALUE
     from PyApex.Errors import ApexError
     
     if not isinstance(Wavelength, (int, float)):
         raise ApexError(APXXXX_ERROR_ARGUMENT_TYPE, "Wavelength")
         sys.exit()
     
     [WavelengthMin, WavelengthMax] = self.GetWavelngthLimits()
     if(Wavelength < WavelengthMin or Wavelength > WavelengthMax):
         raise ApexError(APXXXX_ERROR_ARGUMENT_VALUE, "Wavelength")
         sys.exit()
         
     if not self.__Simulation:
         Command = "FLT[" + str(self.__SlotNumber).zfill(2) + "]:TSTPWL" + \
                   ("%.2f" % Wavelength) + "\n"
         Send(self.__Connexion, Command)
Ejemplo n.º 28
0
    def SetFilterOutput(self, State=False):
        '''
        Sets the state of the internal optical switch
        State can be a boolean or an integer:
            - State = 0 or False : the filter output is not enabled (default)
            - State = 1 or True : the filter output is enabled
        '''
        from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE, APXXXX_ERROR_ARGUMENT_VALUE
        from PyApex.Errors import ApexError

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

        if int(State) not in [0, 1]:
            raise ApexError(APXXXX_ERROR_ARGUMENT_VALUE, "State")
            sys.exit()

        if not self.__Simulation:
            Command = "FILOUTENABLE" + str(int(State)) + "\n"
            Send(self.__Connexion, Command)
Ejemplo n.º 29
0
    def SetAttenuation(self, Attenuation, ChNumber=1):
        '''
        Set attenuation power of the ATT equipment
        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_ATTMIN, AP1000_ATT_ATTMAX, AP1000_ATT_CHNUMBER
        from PyApex.Errors import ApexError

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

                Attenuation = self.__ConvertForWriting(Attenuation)
                if Attenuation < AP1000_ATT_ATTMIN:
                    Attenuation = AP1000_ATT_ATTMIN
                if Attenuation > AP1000_ATT_ATTMAX:
                    Attenuation = AP1000_ATT_ATTMAX
                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) +"]" + ("%.1f" % Attenuation) + "\n"
                    Send(self.__Connexion, Command)

                self.__Attenuation = Attenuation
Ejemplo n.º 30
0
    def SaveToFile(self, FileName, TraceNumber=1, Type="dat"):
        '''
        Save a trace on local hard disk
        FileName is a string representing the path of the file to save
        TraceNumber is an integer between 1 (default) and 6
        Type is the type of the file to save
        Type is a string between the following values:
            - Type = "DAT" : data are saved in a binary format (default)
            - Type = "TXT" : data are saved in a text format
        '''
        from PyApex.Constantes import APXXXX_ERROR_ARGUMENT_TYPE, APXXXX_ERROR_ARGUMENT_VALUE, APXXXX_ERROR_BAD_FILENAME
        from PyApex.Errors import ApexError
        from os.path import isdir, dirname

        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 isdir(dirname(FileName)):
            raise ApexError(APXXXX_ERROR_BAD_FILENAME, str(FileName))
            sys.exit()

        if str(Type).lower() == "txt":
            Type = 1
        else:
            Type = 0

        if not self.__Simulation:
            if Type:
                Command = "SPSAVEB" + str(TraceNumber) + "_" + str(
                    FileName) + "\n"
            else:
                Command = "SPSAVEA" + str(TraceNumber) + "_" + str(
                    FileName) + "\n"
            Send(self.__Connexion, Command)