예제 #1
0
    def _read_spectrum_data(self):

        # Assign endpoint
        vpp43.set_attribute(self._vi, VI_ATTR_USB_BULK_IN_PIPE, 0x82)

        data = ''
        for i in range(32):
            lsbs = vpp43.read(self._vi, 64)
            msbs = vpp43.read(self._vi, 64)

            # Mask MSB high bits - instrument has 12-bit A/D
            msbs = ''.join([chr(ord(byte) & 0x0F) for byte in msbs])

            bs = bytearray(128)
            bs[::2] = lsbs
            bs[1::2] = msbs
            data += str(bs)

        # Read sync packet to check if properly synchronized
        sync_byte = vpp43.read(self._vi, 1)
        if sync_byte != '\x69' or len(data) != 4096:
            raise visa.VisaIOError(OO_ERROR_SYNC)

        # Reassign endpoint
        vpp43.set_attribute(self._vi, VI_ATTR_USB_BULK_IN_PIPE, 0x87)

        return N.fromstring(data, N.int16)
예제 #2
0
    def _read_spectrum_data(self):
        usb_speed = self._usb_speed
        # Only query the value if there is no cached value
        if usb_speed is None:
            usb_speed = self.usb_speed

        n_packets, packet_length = (8, 512) if usb_speed == 'high' else (64, 64)
        # Assign endpoint
        vpp43.set_attribute(self._vi, VI_ATTR_USB_BULK_IN_PIPE, 0x82)

        data = ''
        for i in range(n_packets):
            data += vpp43.read(self._vi, packet_length)

        # Read sync packet to check if properly synchronized
        sync_byte = vpp43.read(self._vi, 1)
        if sync_byte != '\x69' or len(data) != 4096:
            raise visa.VisaIOError(OO_ERROR_SYNC)

        # Reassign endpoint
        vpp43.set_attribute(self._vi, VI_ATTR_USB_BULK_IN_PIPE, 0x81)

        spectrum = N.fromstring(data, N.dtype('<u2'))

        # Query and cache the saturation level if it is not cached
        if self._saturation_level is None:
            vpp43.write(self._vi, '\x05\x11')
            autonull_info = vpp43.read(self._vi, 17)
            self._saturation_level = (65536.0
                / struct.unpack('<H', autonull_info[6:8])[0])
            # Hmmm, it seems that this is an OceanOptics trick to sell
            # spectrometers with much less dynamic range than advertised!

        return spectrum * self._saturation_level
예제 #3
0
    def _read_spectrum_data(self):

        # Assign endpoint
        vpp43.set_attribute(self._vi, VI_ATTR_USB_BULK_IN_PIPE, 0x82)

        data = ''
        for i in range(32):
            lsbs = vpp43.read(self._vi, 64)
            msbs = vpp43.read(self._vi, 64)

            # Mask MSB high bits - instrument has 12-bit A/D
            msbs = ''.join([chr(ord(byte) & 0x0F) for byte in msbs])

            bs = bytearray(128)
            bs[::2] = lsbs
            bs[1::2] = msbs
            data += str(bs)

        # Read sync packet to check if properly synchronized
        sync_byte = vpp43.read(self._vi, 1)
        if sync_byte != '\x69' or len(data) != 4096:
            raise visa.VisaIOError(OO_ERROR_SYNC)

        # Reassign endpoint
        vpp43.set_attribute(self._vi, VI_ATTR_USB_BULK_IN_PIPE, 0x87)

        return N.fromstring(data, N.int16)
예제 #4
0
    def _read_spectrum_data(self):
        usb_speed = self._usb_speed
        # Only query the value if there is no cached value
        if usb_speed is None:
            usb_speed = self.usb_speed

        n_packets, packet_length = (8, 512) if usb_speed == 'high' else (64,
                                                                         64)
        # Assign endpoint
        vpp43.set_attribute(self._vi, VI_ATTR_USB_BULK_IN_PIPE, 0x82)

        data = ''
        for i in range(n_packets):
            data += vpp43.read(self._vi, packet_length)

        # Read sync packet to check if properly synchronized
        sync_byte = vpp43.read(self._vi, 1)
        if sync_byte != '\x69' or len(data) != 4096:
            raise visa.VisaIOError(OO_ERROR_SYNC)

        # Reassign endpoint
        vpp43.set_attribute(self._vi, VI_ATTR_USB_BULK_IN_PIPE, 0x81)

        spectrum = N.fromstring(data, N.dtype('<u2'))

        # Query and cache the saturation level if it is not cached
        if self._saturation_level is None:
            vpp43.write(self._vi, '\x05\x11')
            autonull_info = vpp43.read(self._vi, 17)
            self._saturation_level = (
                65536.0 / struct.unpack('<H', autonull_info[6:8])[0])
            # Hmmm, it seems that this is an OceanOptics trick to sell
            # spectrometers with much less dynamic range than advertised!

        return spectrum * self._saturation_level
 def _doRead(bytes):
     
     if bytes is None:
         ans = instr.read()
     else:
         ans = vpp43.read(instr.vi, bytes)        
     return ans
예제 #6
0
def setPSU(vi, voltage, current):
    buf = ":volt " + str(voltage) + ";:curr " + str(current) + "\n"
    vpp43.write(vi, buf)
    buf = ":apply?\n"
    vpp43.write(vi, buf)
    result = vpp43.read(vi, 256)
    return result
예제 #7
0
파일: sr620.py 프로젝트: q03-iop-cas/qulab
 def __read(self, size):
     """从设备读取 size 个字节"""
     try:
         buff = vpp43.read(self.ins.vi, size)
     except VisaIOWarning:
         pass
     return buff
예제 #8
0
 def _empty_buffer(self):
     '''
     empty buffer of COM port
     '''
     logging.debug(__name__ + ' : do communication with instrument')
     data_out_string =  vpp43.read(self._vi, vpp43.get_attribute(self._vi, vpp43.VI_ATTR_ASRL_AVAIL_NUM))
     return data_out_string
예제 #9
0
    def _send_and_read(self, message):
        '''
        Performs the communication with the device
        Raises an error if one occurred
        Returns a list of bytes

        Input:
            message (string)    : string conform the IVVI protocol

        Output:
            data_out_numbers (int[]) : return message
        '''
        logging.debug(__name__ + ' : do communication with instrument')
        vpp43.write(self._vi, message)
        sleep(0.1)
        data_out_string = vpp43.read(
            self._vi,
            vpp43.get_attribute(self._vi, vpp43.VI_ATTR_ASRL_AVAIL_NUM))
        sleep(0.1)
        data_out_numbers = [ord(s) for s in data_out_string]

        if (data_out_numbers[1] != 0) or (len(data_out_numbers) !=
                                          data_out_numbers[0]):
            logging.error(__name__ + ' : Error while reading : %s',
                          data_out_numbers)

        return data_out_numbers
예제 #10
0
 def _empty_buffer(self):
     '''
     empty buffer of COM port
     '''
     logging.debug(__name__ + ' : do communication with instrument')
     data_out_string = vpp43.read(
         self._vi,
         vpp43.get_attribute(self._vi, vpp43.VI_ATTR_ASRL_AVAIL_NUM))
     return data_out_string
예제 #11
0
    def read(self, c, bytes=None):
        """Read from the GPIB bus.

        If specified, reads only the given number of bytes.
        Otherwise, reads until the device stops sending.
        """
        instr = self.getDevice(c)
        if bytes is None:
            ans = instr.read()
        else:
            ans = vpp43.read(instr.vi, bytes)
        return ans
    def read(self, c, bytes=None):
        """Read from the GPIB bus.

        If specified, reads only the given number of bytes.
        Otherwise, reads until the device stops sending.
        """
        instr = self.getDevice(c)
        if bytes is None:
            ans = instr.read()
        else:
            ans = vpp43.read(instr.vi, bytes)
        return ans
예제 #13
0
    def _read_reply(self, max_sleeps=100):
        '''
        Read reply from the Zaber.
        <max_sleeps> is the maximum number of 50msec sleeps. The default is
        100 for a maximum delay of 5 seconds.
        '''

        i = 0
        while i < max_sleeps:
            navail = vpp43.get_attribute(self._visa.vi, vpp43.VI_ATTR_ASRL_AVAIL_NUM)
            if navail >= 6:
                reply = vpp43.read(self._visa.vi, navail)
                reply = [ord(ch) for ch in reply]
                return reply

            i += 1
            time.sleep(0.05)

        return None
예제 #14
0
파일: Zaber_TNM.py 프로젝트: yiwenchu/qrlab
    def _read_reply(self, max_sleeps=100):
        '''
        Read reply from the Zaber.
        <max_sleeps> is the maximum number of 50msec sleeps. The default is
        100 for a maximum delay of 5 seconds.
        '''

        i = 0
        while i < max_sleeps:
            navail = vpp43.get_attribute(self._visa.vi,
                                         vpp43.VI_ATTR_ASRL_AVAIL_NUM)
            if navail >= 6:
                reply = vpp43.read(self._visa.vi, navail)
                reply = [ord(ch) for ch in reply]
                return reply

            i += 1
            time.sleep(0.05)

        return None
예제 #15
0
파일: SMS.py 프로젝트: CaoXiPitt/Qtlab
    def _read_buffer(self):
        '''
        Returns a string containing the content of the buffer

        Input:
            None

        Output:
            buffer (string) : data in buffer
        '''
        logging.debug(__name__ + ' : Reading buffer')
        tekst = vpp43.read(self._vi,vpp43.get_attribute(self._vi,
            vpp43.VI_ATTR_ASRL_AVAIL_NUM))
        sleep(0.05)

        if (tekst==''):
            return tekst
        elif (tekst[0]=='E'):
            logging.error(__name__  + ' : An error occurred during \
                readout of instrument : ' + tekst)
        else:
            return tekst
예제 #16
0
def read_all(visains):
    """
    Read all available data from the input buffer of visins.
    """

    global _added_filter

    if not _added_filter:
        warnings.filterwarnings("ignore", "VI_SUCCESS_MAX_CNT")
        _added_filter = True

    try:
        buf = ""
        blen = get_navail(visains)
        while blen > 0:
            chunk = vpp43.read(visains, blen)
            buf += chunk
            blen = get_navail(visains)
    except:
        pass

    return buf
예제 #17
0
파일: visafunc.py 프로젝트: yiwenchu/qrlab
def read_all(visains):
    """
    Read all available data from the input buffer of visins.
    """

    global _added_filter

    if not _added_filter:
        warnings.filterwarnings("ignore", "VI_SUCCESS_MAX_CNT")
        _added_filter = True

    try:
        buf = ""
        blen = get_navail(visains)
        while blen > 0:
            chunk = vpp43.read(visains, blen)
            buf += chunk
            blen = get_navail(visains)
    except:
        pass

    return buf
예제 #18
0
    def _read_buffer(self):
        '''
        Returns a string containing the content of the buffer

        Input:
            None

        Output:
            buffer (string) : data in buffer
        '''
        logging.debug(__name__ + ' : Reading buffer')
        tekst = vpp43.read(
            self._vi,
            vpp43.get_attribute(self._vi, vpp43.VI_ATTR_ASRL_AVAIL_NUM))
        sleep(0.05)

        if (tekst == ''):
            return tekst
        elif (tekst[0] == 'E'):
            logging.error(__name__ + ' : An error occurred during \
                readout of instrument : ' + tekst)
        else:
            return tekst
예제 #19
0
    def _send_and_read(self, message):
        '''
        Performs the communication with the device
        Raises an error if one occurred
        Returns a list of bytes

        Input:
            message (string)    : string conform the IVVI protocol

        Output:
            data_out_numbers (int[]) : return message
        '''
        logging.debug(__name__ + ' : do communication with instrument')
        vpp43.write(self._vi, message)
        sleep(0.1)
        data_out_string =  vpp43.read(self._vi, vpp43.get_attribute(self._vi, vpp43.VI_ATTR_ASRL_AVAIL_NUM))
        sleep(0.1)
        data_out_numbers = [ord(s) for s in data_out_string]

        if (data_out_numbers[1] != 0) or (len(data_out_numbers) != data_out_numbers[0]):
            logging.error(__name__ + ' : Error while reading : %s', data_out_numbers)

        return data_out_numbers
예제 #20
0
 def _query_eeprom(self, configuration_index):
     vpp43.write(self._vi, '\x05' + chr(configuration_index))
     answer = vpp43.read(self._vi, 18)
     return answer[2:answer.find('\x00', 2)]  # from byte 3 to the next null
예제 #21
0
파일: visafunc.py 프로젝트: yiwenchu/qrlab
def readn(visains, n):
    return vpp43.read(visains, n)
예제 #22
0
 def _query_status(self):
     vpp43.write(self._vi, '\xFE')
     return vpp43.read(self._vi, 17)
예제 #23
0
 def _query_eeprom(self, configuration_index):
     vpp43.write(self._vi, '\x05' + chr(configuration_index))
     answer = vpp43.read(self._vi, 18)
     return answer[2:answer.find('\x00', 2)]  # from byte 3 to the next null
예제 #24
0
 def _query_status(self):
     vpp43.write(self._vi, '\xFE')
     return vpp43.read(self._vi, 17)
예제 #25
0
파일: Zaber_TNM.py 프로젝트: yiwenchu/qrlab
 def _clear_buffer(self):
     navail = vpp43.get_attribute(self._visa.vi,
                                  vpp43.VI_ATTR_ASRL_AVAIL_NUM)
     if navail > 0:
         reply = vpp43.read(self._visa.vi, navail)
예제 #26
0
 def _read_buffer(self):
     response=vpp43.read(self._vi, vpp43.get_attribute(self._vi,
                         vpp43.VI_ATTR_ASRL_AVAIL_NUM))
     sleep(self._sleeptime)
     return response
예제 #27
0
 def _read_buffer(self):
     response = vpp43.read(
         self._vi,
         vpp43.get_attribute(self._vi, vpp43.VI_ATTR_ASRL_AVAIL_NUM))
     sleep(self._sleeptime)
     return response
예제 #28
0
def readn(visains, n):
    return vpp43.read(visains, n)
예제 #29
0
 def _clear_buffer(self):
     navail = vpp43.get_attribute(self._visa.vi, vpp43.VI_ATTR_ASRL_AVAIL_NUM)
     if navail > 0:
         reply = vpp43.read(self._visa.vi, navail)