예제 #1
0
# Initialize Devices
# ---------------------------------------------------------------------------- #
# Initialize Laser
print("Initializing laser.")
try:
    # Remote Computer via PyroLab
    from pyrolab.api import locate_ns, Proxy
    ns = locate_ns(host="camacholab.ee.byu.edu")
    laser = Proxy(ns.lookup("lasers.TSL550"))
except:
    # Local Computer
    laser = TSL550("COM4")

laser.on()
laser.power_dBm(power_dBm)
laser.open_shutter()
laser.sweep_set_mode(continuous=True,
                     twoway=True,
                     trigger=False,
                     const_freq_step=False)
print("Enabling laser's trigger output.")
laser.trigger_enable_output()
triggerMode = laser.trigger_set_mode("Step")
triggerStep = laser.trigger_set_step(trigger_step)
print("Setting trigger to: {} and step to {}".format(triggerMode, triggerStep))

#Get number of samples to record. Add buffer just in case.
acquire_time = duration + buffer
numSamples = int((acquire_time) * sample_rate)
print("Set for {:.2E} Samples @ {:.2E} Sa/s.".format(numSamples, sample_rate))
예제 #2
0
class TSL550Laser(LaserBase):
    """
    A laser.

    Parameters
    ----------
    pyroname : str
        The name of the PyroLab object as registered with the nameserver.
    ns_host : str, optional
        The hostname of the PyroLab nameserver (default "localhost").
    ns_port : int, optional
        The port of the PyroLab nameserver (default "9090").
    """
    def __init__(self,
                 pyroname: str = "",
                 ns_host: str = "localhost",
                 ns_port: int = 9090):
        super().__init__(pyroname)
        with locate_ns(host=ns_host, port=ns_port) as ns:
            self.driver = Proxy(ns.lookup(pyroname))
            self.driver.autoconnect()

    def on(self, block=False) -> None:
        """
        Turn on the laser.

        If the laser diode is off, there is a warm-up time before the laser
        diode is ready. If block is True, this function will block until the
        warm-up time is complete.

        Parameters
        ----------
        block : bool, optional
            Whether to block until the warm-up time is complete (default False).
        """
        self.driver._pyroClaimOwnership()
        if self.driver.status()[0] != '-':
            self.driver.on()
            if block:
                while self.driver.status()[0] != '-':
                    time.sleep(5.0)
        self.driver.open_shutter()

    def off(self, diode: bool = True) -> None:
        """
        Turns off laser output by closing the shutter and optionally turning off the diode.

        Parameters
        ----------
        diode : bool, optional
            Whether to turn off the diode. If False, the laser diode will be
            turned off. There is a warm-up period to turn the laser back on if
            the diode has been turned off. If True, the laser diode will be
            left on but the shutter will be closed.
        """
        self.driver._pyroClaimOwnership()
        self.driver.close_shutter()
        if not diode:
            self.driver.off()

    def power(self, power: float) -> None:
        """
        Sets the laser power in dBm.

        Parameters
        ----------
        power : float
            The power to set the laser to.
        """
        self.driver._pyroClaimOwnership()
        self.driver.power_dBm(power)

    def wavelength(self, wavelength: float) -> None:
        """
        Sets the laser wavelength in nm.

        Parameters
        ----------
        wavelength : float
            The wavelength to set the laser to.
        """
        self.driver._pyroClaimOwnership()
        self.driver.wavelength(wavelength)

    def sweep(self, num: int = 1) -> None:
        """
        Starts the configured wavelength sweep.

        Parameters
        ----------
        num : int, optional
            The number of times to run the wavelength sweep (default 1).
        """
        self.driver._pyroClaimOwnership()
        self.driver.sweep_start(num)

    def sweep_wavelength(self,
                         wl_start: float = 1500,
                         wl_stop: float = 1630,
                         duration: float = 2,
                         number: int = 1):
        """
        Convenience function to run a continuous wavelength sweep.

        Parameters
        ----------
        wl_start : float, optional
            The starting wavelength (default 1500).
        wl_stop : float, optional
            The ending wavelength (default 1630).
        duration : float, optional
            The duration of the sweep (default 2).
        number : int, optional
            The number of times to run the sweep (default 1).
        """
        self.driver._pyroClaimOwnership()
        self.driver.sweep_wavelength(start=wl_start,
                                     stop=wl_stop,
                                     duration=duration,
                                     number=number)

    def sweep_set_mode(self,
                       continuous: bool = True,
                       twoway: bool = True,
                       trigger: bool = False,
                       const_freq_step: bool = False) -> None:
        """
        Sets the sweep mode.

        Parameters
        ----------
        continuous : bool
            Continuous (``True``, default) or stepwise (``False``).
        twoway : bool
            Two-way (``True``, default) or one-directional with reset
            (``False``).
        trigger : bool
            Start on external trigger (defaults to ``False``).
        const_freq_step : bool
            Constant frequency interval, requires stepwise mode (defaults to
            ``False``).
        """
        self.driver._pyroClaimOwnership()
        self.driver.sweep_set_mode(
            continuous=continuous,
            twoway=twoway,
            trigger=trigger,
            const_freq_step=const_freq_step,
        )

    def set_trigger(self, mode: str, step: float) -> None:
        """
        Enables trigger output.

        The output trigger can be set to fire at the start of a wavelength
        sweep, at the end of a sweep, or at a fixed step. Valid step range is
        0.004 - 160 nm with a minimum step of 0.0001 nm.

        Parameters
        ----------
        mode : str
            The trigger mode. One of: “None”, “Stop”, “Start”, “Step”.
        step : float
            The trigger step size, in nanometers.
        """
        self.driver._pyroClaimOwnership()
        self.driver.trigger_enable_output()
        triggerMode = self.driver.trigger_set_mode(mode)
        triggerStep = self.driver.trigger_step(step)
        return triggerMode, triggerStep

    def wavelength_logging(self) -> None:
        """
        Downloads the wavelength log.

        Returns
        -------
        list
            The last wavelength log.
        """
        self.driver._pyroClaimOwnership()
        return self.driver.wavelength_logging()