Example #1
0
    def __init__(self, name, address, wavemeter, reset=False):
        logging.debug('Initializing fiber switch on port %s.' % address)
        Instrument.__init__(self, name, tags=['physical'])
        self._visainstrument = SerialInstrument(address)
        self._visainstrument.baud_rate = 115200
        self._visainstrument.term_chars = '\n'

        self.wait_time = 0.3
        self._wavemeter = wavemeter

        self.add_parameter('active_port',
                type=types.IntType,
                flags=Instrument.FLAG_GETSET,
                minval=1, maxval=2)
        self.add_parameter('port1_wavelength',
                type=types.FloatType,
                flags=Instrument.FLAG_GET,
                units='nm')
        self.add_parameter('port2_wavelength',
                type=types.FloatType,
                flags=Instrument.FLAG_GET,
                units='nm')
        self.add_parameter('port1_power',
                type=types.FloatType,
                flags=Instrument.FLAG_GET,
                units='mW')
        self.add_parameter('port2_power',
                type=types.FloatType,
                flags=Instrument.FLAG_GET,
                units='mW')
        
        if reset:
            self.reset()
        else:
            self.get_all()
Example #2
0
 def __init__(self, PortName, baud_rate, data_bits, stop_bits, parity,
              term_chars, Echoed, ReportsStatus):
     "PortName = string of VISA resource descriptor or Allias"
     VISABus.__init__(self, PortName)
     self.f = SerialInstrument(PortName,
                               baud_rate=baud_rate,
                               data_bits=data_bits,
                               stop_bits=stop_bits,
                               parity=parity,
                               term_chars=term_chars)
     #print self.deviceIBName, ':clearing the device buffer...'
     #self.f.clear()
     self.echoed = Echoed  # sets whether the transmissions to the device are achoed back to the interface
     self.reportsStatus = ReportsStatus  # sets whether the transmissions
     return
Example #3
0
class Thorlabs_FiberSwitch(Instrument):
    '''
    Thorlabs Fiber Switch

    The switch is being used to switch between two inputs for a connected
    wavemeter. The wavemeter reading should be accessed through this wrapper 
    so that the correct reading is given for the specified port and because
    it will block access during that time for other readings.

    When creating the instrument the used wavemeter should be specified.

    '''

    def __init__(self, name, address, wavemeter, reset=False):
        logging.debug('Initializing fiber switch on port %s.' % address)
        Instrument.__init__(self, name, tags=['physical'])
        self._visainstrument = SerialInstrument(address)
        self._visainstrument.baud_rate = 115200
        self._visainstrument.term_chars = '\n'

        self.wait_time = 0.3
        self._wavemeter = wavemeter

        self.add_parameter('active_port',
                type=types.IntType,
                flags=Instrument.FLAG_GETSET,
                minval=1, maxval=2)
        self.add_parameter('port1_wavelength',
                type=types.FloatType,
                flags=Instrument.FLAG_GET,
                units='nm')
        self.add_parameter('port2_wavelength',
                type=types.FloatType,
                flags=Instrument.FLAG_GET,
                units='nm')
        self.add_parameter('port1_power',
                type=types.FloatType,
                flags=Instrument.FLAG_GET,
                units='mW')
        self.add_parameter('port2_power',
                type=types.FloatType,
                flags=Instrument.FLAG_GET,
                units='mW')
        
        if reset:
            self.reset()
        else:
            self.get_all()

#### initialization related

    def reset(self):
        print __name__ + ' : resetting instrument'

    def get_all(self):
        print __name__ + ' : reading all settings from instrument'
        self.get_active_port()
        self.get_port1_wavelength()
        self.get_port1_power()
        self.get_port2_wavelength()
        self.get_port2_power()

#### communication with machine
    def do_get_active_port(self):
        return self._visainstrument.ask('S?')

    def do_set_active_port(self, port):
        self._visainstrument.write('S %i' %port)
        if self.get_active_port() == port:
            return True
        else:
            raise Warning('The switch did not reply with the expected port.')

    def do_get_port1_wavelength(self):
        if self.get_active_port() == 2:
            self.set_active_port(1)
            msleep(self.wait_time)
        return self._wavemeter.get_wavelength()

    def do_get_port2_wavelength(self):
        if self.get_active_port() == 1:
            self.set_active_port(2)
            msleep(self.wait_time)
        return self._wavemeter.get_wavelength()

    def do_get_port1_power(self):
        if self.get_active_port()==2:
            self.set_active_port(1)
            msleep(self.wait_time)
        return self._wavemeter.get_power()

    def do_get_port2_power(self):
        if self.get_active_port()==1:
            self.set_active_port(2)
            msleep(self.wait_time)
        return self._wavemeter.get_power()