Ejemplo n.º 1
0
    def __init__(self):

        self._dev = usb.core.find(idVendor=0x2457, idProduct=0x101E)
        if self._dev is None:
            raise _OOError('No OceanOptics USB2000+ spectrometer found!')
        else:
            print('*NOTE*: Currently the first device matching the '
                  'Vendor/Product id is used')

        # This information comes from the OEM-Datasheet
        # "http://www.oceanoptics.com/technical"
        #       "/engineering/OEM%20Data%20Sheet%20--%20USB2000+.pdf"
        self._EP1_out = 0x01
        self._EP1_in = 0x81
        self._EP2_in = 0x82
        self._EP6_in = 0x86
        self._EP1_in_size = 64
        self._EP2_in_size = 512
        self._EP6_in_size = 512

        # This part makes the initialization a little bit more robust
        self._dev.set_configuration()
        self._initialize()
        #<robust>#
        for i in range(10):
            try:
                self._usbcomm = self._query_status()['usb_speed']
                break
            except usb.core.USBError:
                pass
        else:
            raise _OOError('Initialization USBCOM')
        self.integration_time(1000)  # sets self._it
        for i in range(10):
            try:
                self._request_spectrum()
                break
            except:
                pass
        else:
            raise _OOError('Initialization SPECTRUM')
        #</robust>#

        self._wl = self._get_wavelength_calibration()
        self._nl = self._get_nonlinearity_calibration()
        self._st = self._get_saturation_calibration()
        self.Serial = self._get_serial()
Ejemplo n.º 2
0
    def __init__(self):
        
        self._dev = usb.core.find(idVendor=0x2457, idProduct=0x101E)
        if self._dev is None:
            raise _OOError('No OceanOptics USB2000+ spectrometer found!')
        else:
            print ('*NOTE*: Currently the first device matching the '
                   'Vendor/Product id is used')
        
        # This information comes from the OEM-Datasheet
        # "http://www.oceanoptics.com/technical"
        #       "/engineering/OEM%20Data%20Sheet%20--%20USB2000+.pdf"
        self._EP1_out = 0x01
        self._EP1_in = 0x81
        self._EP2_in = 0x82
        self._EP6_in = 0x86
        self._EP1_in_size = 64
        self._EP2_in_size = 512
        self._EP6_in_size = 512

        # This part makes the initialization a little bit more robust
        self._dev.set_configuration()
        self._initialize()
        #<robust>#
        for i in range(10):
            try:
                self._usbcomm = self._query_status()['usb_speed']
                break
            except usb.core.USBError: pass
        else: raise _OOError('Initialization USBCOM')
        self.integration_time(1000) # sets self._it
        for i in range(10):
            try:
                self._request_spectrum()
                break
            except: pass
        else: raise _OOError('Initialization SPECTRUM')
        #</robust>#

        self._wl = self._get_wavelength_calibration()
        self._nl = self._get_nonlinearity_calibration()
        self._st = self._get_saturation_calibration()
        self.Serial = self._get_serial()
Ejemplo n.º 3
0
 def _request_spectrum(self):
     """ 0x09 request spectra """
     # XXX: 100000 was an arbitary choice. Should probably be a little less than the USB timeout
     self._dev.write(self._EP1_out, struct.pack('<B', 0x09))
     time.sleep( max(self._it - 100000, 0) * 1e-6 )
     if self._usbcomm == 0x80: #HIGHSPEED
         ret = [self._dev.read(self._EP2_in, 512) for _ in range(8)]
     else: # _usbcomm == 0x00  #FULLSPEED
         ret = [self._dev.read(self._EP2_in, 64) for _ in range(66)]
     ret = sum(ret[1:], ret[0])
     spectrum = struct.unpack('<'+'h'*2048, ret)
     sync = self._dev.read(self._EP2_in, 1)
     if sync[0] != 0x69:
         raise _OOError('request_spectrum: Wrong answer')
     return spectrum
Ejemplo n.º 4
0
 def _request_spectrum(self):
     """ 0x09 request spectra """
     # XXX: 100000 was an arbitary choice. Should probably be a little less than the USB timeout
     self._dev.write(self._EP1_out, struct.pack('<B', 0x09))
     time.sleep( max(self._it - 100000, 0) * 1e-6 )
     if self._usbcomm == 0x80: #HIGHSPEED
         ret = [self._dev.read(self._EP2_in, 512) for _ in range(8)]
     else: # _usbcomm == 0x00  #FULLSPEED
         ret = [self._dev.read(self._EP2_in, 64) for _ in range(64)]
     ret = sum(ret[1:], ret[0])
     spectrum = struct.unpack('<'+'h'*2048, ret)
     sync = self._dev.read(self._EP2_in, 1)
     if sync[0] != 0x69:
         raise _OOError('request_spectrum: Wrong answer')
     return spectrum
Ejemplo n.º 5
0
 def _get_nonlinearity_calibration(self):
     if int(self._query_information(14)) != 7:
         # Don't care about this right now
         raise _OOError('This spectrometer has less correction factors')
     return [float(self._query_information(i)) for i in range(6,14)]
Ejemplo n.º 6
0
 def _get_nonlinearity_calibration(self):
     if int(self._query_information(14)) != 7:
         # Don't care about this right now
         raise _OOError('This spectrometer has less correction factors')
     return [float(self._query_information(i)) for i in range(6,14)]