Ocean Optics spectrometer
| 68 | |
| 69 | |
| 70 | class USB4000(USBDriver): |
| 71 | """Ocean Optics spectrometer |
| 72 | """ |
| 73 | |
| 74 | def __init__(self, serial_number=None, **kwargs): |
| 75 | super().__init__(vendor=0x2457, product=0x1022, serial_number=serial_number, **kwargs) |
| 76 | |
| 77 | self._spec_hi = usb_find_desc(self.usb_inf, bEndpointAddress=0x82) |
| 78 | self._spec_lo = usb_find_desc(self.usb_inf, bEndpointAddress=0x86) |
| 79 | |
| 80 | # initialize spectrometer |
| 81 | self.initialize() |
| 82 | |
| 83 | def initialize(self): |
| 84 | """Ends the initialization command to the USB4000 spectrometer |
| 85 | |
| 86 | This command initializes certain parameters on the USB4000 and sets internal variables |
| 87 | based on the USB communication speed. This command is called at object instantiation. |
| 88 | """ |
| 89 | self.usb_send_ep.write(struct.pack('<B', 0x01)) |
| 90 | |
| 91 | integration_time = Feat(units='microsecond', limits=(10, 65535000)) |
| 92 | |
| 93 | @integration_time.setter |
| 94 | def integration_time(self, dt): |
| 95 | """Sets the integration time to use by the spectrometer in microseconds |
| 96 | |
| 97 | This command sets the integration time that the USB4000 uses when acquiring spectra. The |
| 98 | value is passed as a 32 bit integer and has a valid range between 10 and 65,535,000 us. |
| 99 | """ |
| 100 | |
| 101 | cmd = struct.pack('<BI', 0x02, dt) |
| 102 | self.usb_send_ep.write(cmd) |
| 103 | |
| 104 | @DictFeat(keys=tuple(range(32))) |
| 105 | def query_config(self, position): |
| 106 | """returns the value stored in register `reg` of the spectrometer |
| 107 | """ |
| 108 | cmd = struct.pack('<2B', 0x05, position) |
| 109 | self.usb_send_ep.write(cmd) |
| 110 | resp = bytearray(self.usb_recv_ep.read(64, timeout=1000)) |
| 111 | |
| 112 | # Check that proper echo is returned |
| 113 | assert resp[0:2] == bytearray([0x05, position]) |
| 114 | |
| 115 | config.update({config_regs[x] : resp[2:].decode('ascii', errors='ignore').strip('\x00')}) |
| 116 | |
| 117 | return config |
| 118 | |
| 119 | def reset(self): |
| 120 | self.usb.reset() |
| 121 | |
| 122 | @Feat(units='degree_celsius') |
| 123 | def pcb_temperature(self): |
| 124 | cmd = struct.pack('<B', 0x6C) |
| 125 | self.usb_send_ep.write(cmd) |
| 126 | resp = bytearray(self.usb_recv_ep.read(3, timeout=1000)) |
| 127 |