示例#1
0
    def SetPower(self, Power):
        '''
        Set output power of the New Focus TLS equipment
        Power is expressed in the unit defined by the GetUnit() method
        '''
        from PyNewFocus.Constants import NF_ERROR_ARGUMENT_TYPE, NF_TLS_PWMIN, NF_TLS_PWMAX
        from PyNewFocus.Errors import NFError

        try:
            Power = float(Power)
        except:
            self.Close(True)
            raise NFError(NF_ERROR_ARGUMENT_TYPE, "Power")

        if Power < NF_TLS_PWMIN:
            Power = NF_TLS_PWMIN
        if Power > NF_TLS_PWMAX:
            Power = NF_TLS_PWMAX

        if not self.Simulation:
            Command = "POW " + ("%2.2f" % Power).zfill(5) + self.Units[
                self.UnitIndex].upper() + "\n"
            self.Send(Command)

        if self.UnitIndex == 1:
            Power = self.ConvertToLog(Power)
        self.Power = Power
示例#2
0
    def Send(self, Command):
        '''
        Send a string Command to the TLS equipment (ending character must be \'\n')
        '''
        from PyNewFocus.Constants import NF_ERROR_ARGUMENT_TYPE, NF_ERROR_COMMUNICATION
        from PyNewFocus.Errors import NFError

        if not isinstance(Command, str):
            self.Close(True)
            raise NFError(NF_ERROR_ARGUMENT_TYPE, "Command")

        if not self.Simulation:
            try:
                self.Connexion.write(Command.encode('utf-8'))
            except:
                self.Close(True)
                raise NFError(NF_ERROR_COMMUNICATION, "Command")
示例#3
0
    def Receive(self, ByteNumber=1024):
        '''
        Receive a string from the TLS equipment
        ByteNumber is an integer (default to 1024) representing the number of bytes to receive
        '''
        from PyNewFocus.Constants import NF_ERROR_ARGUMENT_TYPE, NF_ERROR_BADCOMMAND
        from PyNewFocus.Errors import NFError

        if not isinstance(ByteNumber, int):
            self.Close(True)
            raise NFError(NF_ERROR_ARGUMENT_TYPE, "ByteNumber")

        if not self.Simulation:
            try:
                data = self.Connexion.readline()
            except:
                self.Close(True)
                raise NFError(NF_ERROR_BADCOMMAND, "Last command")
            else:
                return data.decode('utf-8')[1:]
示例#4
0
    def SetUnit(self, Unit):
        '''
        Set the power unit of the New Focus TLS equipment
        Unit is a string which could be "dBm" for logaritmic or "mW" for linear power
        '''
        from PyNewFocus.Constants import NF_ERROR_ARGUMENT_TYPE, NF_ERROR_ARGUMENT_VALUE
        from PyNewFocus.Errors import NFError

        if not isinstance(Unit, str):
            self.Close(True)
            raise NFError(NF_ERROR_ARGUMENT_TYPE, "Unit")
        if not Unit.lower() in self.ValidUnits:
            self.Close(True)
            raise NFError(NF_ERROR_ARGUMENT_VALUE, "Unit")
        else:
            self.UnitIndex = self.ValidUnits.index(Unit.lower())

        if not self.Simulation:
            Command = "POW:UNIT " + Unit.upper() + "\n"
            self.Send(Command)
示例#5
0
    def ConvertToLin(self, LogPower):
        '''
        Return a converted linear power (mW) from a logaritmic one (dBm)
        LogPower is the dBm power to convert
        '''
        from PyNewFocus.Constants import NF_ERROR_ARGUMENT_TYPE
        from PyNewFocus.Errors import NFError

        try:
            LogPower = float(LogPower)
        except:
            self.Close(True)
            raise NFError(NF_ERROR_ARGUMENT_TYPE, "LogPower")

        return 10**(LogPower / 10)
示例#6
0
    def ConvertToLog(self, LinearPower):
        '''
        Return a converted logaritmic power (dBm) from a linear one (mW)
        LinearPower is the mW power to convert
        '''
        from PyNewFocus.Constants import NF_ERROR_ARGUMENT_TYPE
        from PyNewFocus.Errors import NFError
        from math import log10 as log

        try:
            LinearPower = float(LinearPower)
        except:
            self.Close(True)
            raise NFError(NF_ERROR_ARGUMENT_TYPE, "LinearPower")

        return 10 * log(LinearPower)
示例#7
0
    def SetWavelength(self, Wavelength):
        '''
        Set wavelength of the New Focus TLS equipment
        Wavelength is expressed in nm
        '''
        from PyNewFocus.Constants import NF_ERROR_ARGUMENT_TYPE, NF_TLS_WLMIN, NF_TLS_WLMAX
        from PyNewFocus.Errors import NFError

        try:
            Wavelength = float(Wavelength)
        except:
            self.Close(True)
            raise NFError(NF_ERROR_ARGUMENT_TYPE, "Wavelength")

        if Wavelength < NF_TLS_WLMIN:
            Wavelength = NF_TLS_WLMIN
        if Wavelength > NF_TLS_WLMAX:
            Wavelength = NF_TLS_WLMAX

        if not self.Simulation:
            Command = "WAV " + ("%4.3f" % Wavelength).zfill(8) + "\n"
            self.Send(Command)

        self.Wavelength = Wavelength