Ejemplo n.º 1
0
    def get_curve(self, source=None):
        """
        Fetch a trace.

        :param source: Channel to retrieve. Defaults to
            value of :attr:`data_source`. Valid channels are
            `CH1`, `CH2`, `CH3`, `CH4`, `MATH`, `MATH1` (same as
            `MATH`), `REF1`, `REF2`, `REF3`, or `REF4`.
        :returns: A numpy array representing the current waveform.

        """
        if source is None:
            source = self.data_source
        else:
            self.data_source = source
        if not self.is_active(source):
            raise InstrumentError('%s not turned on' % source)

        fmt = '>' if self.wfmpre['BYT_OR'] == 'MSB' else '<'
        fmt += 'i' if self.wfmpre['BN_FMT'] == 'RI' else 'u'
        fmt += str(self.wfmpre['BYT_NR'])

        self.bus.write('CURV?')
        result = self.bus.read()  # reads either everything (GPIB)
        # or a single byte (RS-232)
        if result == '#':
            meta_len = int(self.bus.read(1))
            data_len = int(self.bus.read(meta_len))
            result = self.bus.read(data_len)
            self.bus.read(1)  # read final newline
        elif len(result) == 1:
            # if we received something other than a pound sign
            raise InstrumentError('Unknown first byte: %s' % result)

        return numpy.fromstring(result, dtype=fmt)
Ejemplo n.º 2
0
 def set_DAC(self, n, value):
     """ set one of the DAC ports. Provide value in volts."""
     if n not in self.DAC_range:
         err = "Indicate DAC in range %s" % (self.DAC_range)
         raise InstrumentError(err)
     if abs(value) > 10.5:
         err = "DAC range is [-10.5V, 10.5V]"
         raise InstrumentError(err)
     response = self.bus.write("AUXV %d, %.3f" % (n, value))
Ejemplo n.º 3
0
    def boot_status_check(self):
        """Check the boot status of the controller.

        - \* : Just Autobauded
        - B : Boot Acknowledged
        - F : Just Flashed
        """
        self.bus.readall()
        resp = self.bus.ask(' ')  # send autobaud character
        if len(resp) == 0:
            raise InstrumentError("750M did not give a boot status")
        elif resp[0] in ("*", "F", "B"):
            return resp[0]
        else:
            raise InstrumentError("Unknown 750M boot status: %s" % resp)
Ejemplo n.º 4
0
 def get_DAC(self, n):
     """ read one of the DAC ports. Return value in volts."""
     if n not in self.DAC_range:
         err = "Indicate DAC in range %s" % (self.DAC_range)
         raise InstrumentError(err)
     response = self.bus.ask("AUXV?%d" % n)
     return float(response)
Ejemplo n.º 5
0
 def get_ADC(self, n):
     """ read one of the ADC ports. Return value in volts."""
     if n not in self.ADC_range:
         err = "Indicate ADC in range %s" % (self.ADC_range)
         raise InstrumentError(err)
     response = self.bus.ask(self.ADC_cmd % n)
     return float(response)
Ejemplo n.º 6
0
    def __init__(self, bus):
        self.bus = bus

        # verify lockin identity
        resp = self.bus.ask("ID")
        if resp != '5110':
            raise InstrumentError('5110 lockin not found')
Ejemplo n.º 7
0
 def set_wavelength(self, wl):
     """Move to the wavelength value specified.
     contingent on proper calibration, of course.
     """
     if wl < 0 or wl > 1500:
         raise InstrumentError("Out of Range")
     distance_to_move = wl - self.get_wavelength()
     self.rel_move(distance_to_move)
Ejemplo n.º 8
0
 def _hi_iq(self):
     """Send the HI IQ character to the controller.
     (Duplicates functionality of F7-247.vi.)
     Returns True if it's ok to flash the controller
     afterward.
     """
     self.bus.readall()
     resp = self.bus.ask("\xF7")
     if resp[0] == "=":
         return True
     else:
         raise InstrumentError("750M HI IQ command failed")
Ejemplo n.º 9
0
 def init_hardware(self):
     """Initialize 750M hardware. I don't know why this
     works, I just copied Yan's LabView routine.
     """
     status = self.boot_status_check()
     if status == "*":
         self._hi_iq()  # * -> B
         self._flash()  # B -> F
     status = self.boot_status_check()
     if status == "F":
         return True
     else:
         raise InstrumentError("750M hardware init failed.")
Ejemplo n.º 10
0
    def set_timediv(self, to):
        """
        Set time per division, in seconds.

        :param to:  Desired seconds per division.
                    Acceptable values range from 10 seconds to 1, 2, or
                    4ns, depending on model, in a 1-2-4 sequence.
        :type to:   float

        """
        to = sciround(to, 1)
        if to in self._acceptable_timedivs:
            self.bus.write('HOR:MAI:SCA %.0E' % to)
        else:
            raise InstrumentError('Timediv not in %s' %
                                  str(self._acceptable_timedivs))
Ejemplo n.º 11
0
    def wait_for_ok(self, expected_bytes=1):
        """
        Wait indefinitely for the 'o' status byte.

        This function waits until a certain number of bytes
        (usually just one) are present on the bus. When
        that data arrives, the first bye is read
        and checked to make sure it's the "okay" status.

        """
        while self.bus.inWaiting() < expected_bytes:
            # as long as the buffer is empty, hang out
            sleep(0.050)
        # read the status byte when it arrives
        resp = self.bus.read()
        if resp != 'o':
            raise InstrumentError("750M operation failed: %s" % resp)
Ejemplo n.º 12
0
    def senddata(self, throw=True):
        """
        Send image data to the display server.

        If throw = False is given, will fail silently
        if there is no display server.

        """
        if self.proxy is not None:
            data = xmlrpclib.Binary(self.png.read())
            try:
                self.proxy.setImageData(data)
            except xmlrpclib.ProtocolError:
                print 'error talking to display server, retrying once'
                self.proxy.setImageData(data)
        elif throw:
            raise InstrumentError("No display server defined")
Ejemplo n.º 13
0
    def write(self, cmd):
        """
        Issue a command to the laser.

        This takes care of two things:
            - Formats the command with ``@`` if using RS-232
            - Verifies that the laser responds with ``OK``

        """
        # if communicating over serial, commands must start with '@'
        prepend = '@' if self.is_serial else ''
        resp = self.bus.ask(prepend + cmd).rstrip()
        if resp != 'OK':
            # try one more time
            resp = self.bus.ask(prepend + cmd)
        if resp != 'OK':
            msg = "laser didn't like command: %s. it says: %s"
            raise InstrumentError(msg % (cmd, resp))
Ejemplo n.º 14
0
    def get_spectrum(self):
        """
        Takes a shot on the CCD.

        Returns a 2-tuple ``(wl, ccd)``.

        ``wl``: a 1-D array of the horizontal (wavelength) axis.
        ``ccd``: a 2-D array of CCD counts.

        To collapse ``ccd`` into a 1D array matching ``wl``,
        sum over axis 0:

        >>> wl,ccd = clnt.get_spectrum()
        >>> line, = pylab.plot(wl,ccd.sum(axis=0))

        """

        self.sock.send('Q')
        self.sock.send(str(100 * self.center_wl))

        response = self.sock.recv(7)
        if not response:
            raise InstrumentError(
                'No response from Labview client, try reconnecting')

        datalen = int(response)
        data = ''

        while datalen > 0:
            # read data in chunks
            dt = self.sock.recv(datalen)
            data += dt
            datalen -= len(dt)

        data = data.split("\n")[:-1]
        for i in range(len(data)):
            data[i] = data[i].split("\t")

        data = n.array(data, dtype=float)

        wl = data[0]
        ccd = data[1:]

        return wl, ccd
Ejemplo n.º 15
0
 def get_ADC(self, n):
     """Read one of the four ADC ports. Return value in volts."""
     if n not in range(1, 4):
         raise InstrumentError("Indicate ADC between 1 and 4")
     response = self.bus.ask("ADC %d" % n)
     return 0.001 * int(response)