コード例 #1
0
    def set_wavelength(self, wavelength):
        """Set wavelength

        Moves grating to change central wavelength of spectrograph.

        Args:
            wavelength (float): Wavelength to set in nanometres.

        Raises:
            winspec.WinspecError for hardware problems.
        """
        if not self._lock.acquire(blocking=False):
            raise WinspecError(WinspecErrorCodes.SpectrometerBusy, 
                               'Unable to update wavelength due to concurrent operation')
        try:
            logging.info('Set wavelength {}'.format(wavelength))
            #pylint: disable=no-member
            win32.pythoncom.CoInitialize()
            spectrograph = self._get_spectrograph()
            
            retval = spectrograph.SetParam(WinSpecLib.SPT_NEW_POSITION, float(wavelength))
            
            if retval == WinSpecLib.WRONG_WAVELENGTH:
                raise WinspecError(WinspecErrorCodes.OutOfRange,
                                   'Wavelength out of range')
            elif retval != 0:
                self._raise_hw_error(retval)
            
            retval = spectrograph.Move()
            
            if retval != 0:
                self._raise_hw_error(retval)
            
        finally:
            self._lock.release()
コード例 #2
0
    def set_exposure_time(self, exp_time):
        """Set exposure time.

        Args:
            exp_time (float): Exposure time in seconds.
        
        Raises:
            winspec.WinspecError for hardware problems.
        """
        if not self._lock.acquire(blocking=False):
            raise WinspecError(WinspecErrorCodes.SpectrometerBusy, 
                               'Unable to update wavelength due to concurrent operation')
        try:
            logging.info('Set exposure time {}'.format(exp_time))
            #pylint: disable=no-member
            win32.pythoncom.CoInitialize()
            wx32_expt = win32.Dispatch("WinX32.ExpSetup")
            
            retval = wx32_expt.SetParam(WinSpecLib.EXP_EXPOSURE, float(exp_time))
            
            if retval != 0:
                self._raise_hw_error(retval)
            
        finally:
            self._lock.release()
コード例 #3
0
    def _raise_hw_error(self, retval='unknown'):
        """Raise generic WinspecError in response to non-zero return value.

        Args:
            retval (int): The non-zero return value.
        """
        raise WinspecError(WinspecErrorCodes.HardwareError,
                           'Spectrometer error {}'.format(retval))
コード例 #4
0
    def acquire_spectrum(self):
        """Acquire spectrum.

        Returns::
            [wavelength[], intensity[]]
        """
        if not self._lock.acquire(blocking=False):
            raise WinspecError(WinspecErrorCodes.SpectrometerBusy,
                               'Unable to start acquisition due to concurrent operation')
        try:
            logging.info('Acquire spectrum')
            #pylint: disable=no-member
            win32.pythoncom.CoInitialize()
            wx32_expt = win32.Dispatch("WinX32.ExpSetup")
            wx32_doc = win32.Dispatch("WinX32.DocFile")
            
            retval = wx32_expt.Start(wx32_doc)[0]
            
            if retval != True:
                self._raise_hw_error(retval)

            while True:
                running, status = wx32_expt.GetParam(WinSpecLib.EXP_RUNNING)
                if status != 0:
                    self._raise_hw_error(status)
                if not running:
                    break
                time.sleep(0.1)

            ptr = ctypes.POINTER(ctypes.c_float)

            raw_spectrum_buffer = wx32_doc.GetFrame(1, ptr)

            intensity = np.array(raw_spectrum_buffer, dtype=np.uint16).flatten()

            calibration = wx32_doc.GetCalibration()
            
            poly_coeffs = np.zeros(calibration.Order + 1)

            for i in range(calibration.Order + 1):
                poly_coeffs[i] = calibration.PolyCoeffs(i)

            wavelength = np.polyval(poly_coeffs[::-1], np.arange(1, 1+len(intensity)))

            return [wavelength.tolist(), intensity.tolist()]
        
        finally:
            self._lock.release()
コード例 #5
0
    def acquire_spectrum(self):
        """Acquire spectrum.

        Returns::
            [wavelength[], intensity[]]
        """
        if not self._lock.acquire(blocking=False):
            raise WinspecError(WinspecErrorCodes.SpectrometerBusy,
                               'Unable to start acquisition due to concurrent operation')
        try:
            logging.info('Acquire spectrum')
            time.sleep(self.exposure)
            return [[0, 1, 2], [3, 4, 5]]

        finally:
            self._lock.release()
コード例 #6
0
    def set_exposure_time(self, exp_time):
        """Set exposure time.

        Args:
            exp_time (float): Exposure time in seconds.
        
        Raises:
            winspec.WinspecError for hardware problems.
        """
        if not self._lock.acquire(blocking=False):
            raise WinspecError(WinspecErrorCodes.SpectrometerBusy, 
                               'Unable to update wavelength due to concurrent operation')
        try:
            logging.info('Set exposure time {}'.format(exp_time))
            time.sleep(1)
            self.exposure = exp_time
            
        finally:
            self._lock.release()
コード例 #7
0
    def set_wavelength(self, wavelength):
        """Set wavelength

        Moves grating to change central wavelength of spectrograph.

        Args:
            wavelength (float): Wavelength to set in nanometres.

        Raises:
            winspec.WinspecError for hardware problems.
        """
        if not self._lock.acquire(blocking=False):
            raise WinspecError(WinspecErrorCodes.SpectrometerBusy, 
                               'Unable to update wavelength due to concurrent operation')
        try:
            logging.info('Set wavelength {}'.format(wavelength))
            time.sleep(1)
            self.wavelength = wavelength
        finally:
            self._lock.release()