Wasatch.VCPP 1.0.19
Visual C++ driver for Wasatch Photonics spectrometers
Spectrometer.h
Go to the documentation of this file.
1
8#pragma once
9
10#ifdef USE_LIBUSB_WIN32
11#include "libusb.h"
12#define WPVCPP_UDEV_TYPE usb_dev_handle
13#else
14//#include <libusb-1_0.h>
15#include <libusb.h>
16#define WPVCPP_UDEV_TYPE libusb_device_handle
17#endif
18
19#include "EEPROM.h"
20#include "Logger.h"
21
22#include <vector>
23#include <mutex>
24
25namespace WasatchVCPP
26{
27 class Driver;
28
29
37 {
38 public:
42 {
43 Success = 0,
44 Error = -1,
45 InvalidSpectrometer = -2,
46 InsufficientStorage = -3,
47 NoLaser = -4,
48 NotInGaAs = -5,
49 InvalidGain = -256,
50 InvalidTemperature = -999,
51 InvalidOffset = -32768
52 };
53
54 Spectrometer(WPVCPP_UDEV_TYPE* udev, int pid, int index, Logger& logger);
56
57 bool close();
58
59 EEPROM eeprom;
60 Driver* driver = nullptr; // still needed?
61
62 // public metadata
63 int pid = 0;
64 int index = -1;
65 std::vector<double> wavelengths;
66 std::vector<double> wavenumbers;
67 bool isARM();
68 bool isInGaAs();
69 bool isMicro();
70
81 int maxTimeoutMS = 1000;
82
83 // cached properties
84 int pixels = 0;
85 std::string firmwareVersion;
86 std::string fpgaVersion;
87 int integrationTimeMS = 1;
88 bool laserEnabled = false;
89 bool laserPowerHighResolution = true;
90 bool laserPowerRequireModulation = false;
91 bool modEnabled = false;
92 float laserPowerMw = 0.0;
93 float modWidthus = 0.0;
94 float modPeriodus = 0.0;
95 float laserPowerPerc = 0.0;
96 float lastAppliedLaserPower = 0.0;
97 float nextAppliedLaserPower = 0.0;
98 int detectorTECSetointDegC = ErrorCodes::InvalidTemperature;
99 bool srm_in_EEPROM = false;
100
101 // opcodes
102 bool setIntegrationTimeMS(unsigned long ms);
103 bool setLaserEnable(bool flag);
104 bool setDetectorGain(float value);
105 bool setDetectorGainOdd(float value);
106 bool setDetectorOffset(int16_t value);
107 bool setDetectorOffsetOdd(int16_t value);
108 bool setDetectorTECEnable(bool flag);
109 bool setDetectorTECSetpointDegC(int value);
110 bool setHighGainModeEnable(bool flag);
111 bool setLaserPowerPerc(float percent);
112 std::string getFirmwareVersion();
113 std::string getFPGAVersion();
114 int32_t getDetectorTemperatureRaw();
115 float getDetectorTemperatureDegC();
116 unsigned long getIntegrationTimeMS();
117 bool getLaserEnable();
118 float getDetectorGain();
119 float getDetectorGainOdd();
120 int getDetectorOffset();
121 int getDetectorOffsetOdd();
122 bool getDetectorTECEnable();
123 int getDetectorTECSetpointDegC();
124 bool getHighGainModeEnable();
125
126 // public to support wp_send/read_control_msg()
127 int sendCmd(uint8_t bRequest, uint16_t wValue = 0, uint16_t wIndex = 0, uint8_t* data = NULL, int len = 0);
128 bool setModEnable(bool flag);
129 bool setModPeriodus(int us);
130 bool setModWidthus(int us);
131 int getModEnabled(void);
132 uint64_t getModPeriodus(void);
133 bool setLaserPowermW(float mW_in);
134 std::vector<uint8_t> getCmd(uint8_t bRequest, int len, uint16_t wIndex=0, int fullLen=0);
135
136 // acquisition
137 std::vector<double> getSpectrum();
138 bool cancelOperation(bool blocking);
139
141 // Private attributes
143 private:
144 WPVCPP_UDEV_TYPE* udev = nullptr;
145
146 std::vector<uint8_t> endpoints;
147 std::vector<uint8_t> bufSubspectrum;
148 int pixelsPerEndpoint = 0;
149
150 bool detectorTECSetpointHasBeenSet = false;
151 bool acquiring = false;
152 bool operationCancelled = false;
153 int cancelledIntegrationTimeMS = 0;
154 bool lastAcquisitionWasCancelled = false;
155
156 std::mutex mutAcquisition;
157 std::mutex mutComm;
158
159 Logger& logger;
160
162 // Private methods
164 private:
165 // initialization
166 bool readEEPROM();
167
168 // acquisition
169 std::vector<uint16_t> getSubspectrum(uint8_t ep, long allocatedMS);
170 long generateTotalWaitMS();
171
172 // control messages
173 int sendCmd(uint8_t bRequest, uint16_t wValue, uint16_t wIndex, std::vector<uint8_t> data);
174 std::vector<uint8_t> getCmd2(uint16_t wValue, int len, uint16_t wIndex=0, int fullLen=0);
175 std::vector<uint8_t> getCmdReal(uint8_t bRequest, uint16_t wValue, uint16_t wIndex, int len, int fullLen);
176
177 // utility
178 bool isSuccess(unsigned char opcode, int result);
179 uint16_t serializeGain(float value);
180 float deserializeGain(const std::vector<uint8_t>& data);
181 inline unsigned long clamp(unsigned long value, unsigned long min, unsigned long max);
182 bool lockComm();
183 void unlockComm();
184 };
185}
interface of WasatchVCPP::EEPROM
interface of WasatchVCPP::Logger
This is an internal class encapsulating state and control of all connected spectrometers.
Definition: Driver.h:55
Internal class encapsulating the EEPROM and its fields.
Definition: EEPROM.h:23
Internal logger (outputs to textfile if configured).
Definition: Logger.h:18
Internal class encapsulating state and control of one spectrometer.
Definition: Spectrometer.h:37
float getDetectorGain()
Definition: Spectrometer.cpp:807
float getDetectorGainOdd()
Definition: Spectrometer.cpp:811
int maxTimeoutMS
Other Wasatch drivers don't really have this concept...basically, all blocking reads to bulk endpoint...
Definition: Spectrometer.h:81
bool isInGaAs()
Definition: Spectrometer.cpp:1005
int sendCmd(uint8_t bRequest, uint16_t wValue=0, uint16_t wIndex=0, uint8_t *data=NULL, int len=0)
Write data to the spectrometer.
Definition: Spectrometer.cpp:855
int32_t getDetectorTemperatureRaw()
Definition: Spectrometer.cpp:483
std::vector< uint8_t > getCmd(uint8_t bRequest, int len, uint16_t wIndex=0, int fullLen=0)
This is the standard "getter opcode" function.
Definition: Spectrometer.cpp:900
ErrorCodes
keep synchronized with WasatchVCPP.h WP_ERROR_*
Definition: Spectrometer.h:42
bool cancelOperation(bool blocking)
Attempt to cancel an ongoing integration.
Definition: Spectrometer.cpp:525
Namespace encapsulating the internal implementation of WasatchVCPP; customers would not normally acce...
Definition: Driver.h:26