|
Wasatch.VCPP 1.0.19
Visual C++ driver for Wasatch Photonics spectrometers
|
Implementation of the flattened C API exported by WasatchVCPP.dll. More...
#include "pch.h"#include "WasatchVCPP.h"#include <algorithm>#include <vector>#include <string>#include <map>#include <math.h>#include <string.h>#include "Util.h"#include "Logger.h"#include "Driver.h"#include "Spectrometer.h"Functions | |
| int | exportString (string s, char *buf, int len) |
| copy a std::string to a C string More... | |
| int | wp_open_all_spectrometers () |
| Connects to and initializes all enumerated USB spectrometers. More... | |
| int | wp_close_spectrometer (int specIndex) |
| Closes the specified spectrometer. More... | |
| int | wp_close_all_spectrometers () |
| Closes all connected spectrometers. More... | |
| void | wp_destroy_driver () |
| Permanently releases all objects from memory. More... | |
| int | wp_get_library_version (char *value, int len) |
| Obtains the version number of the WasatchVCPP library itself. More... | |
| int | wp_get_number_of_spectrometers () |
| Returns number of spectrometers previously opened. More... | |
| int | wp_get_pixels (int specIndex) |
| Returns the number of pixels in the selected spectrometer.o. More... | |
| int | wp_get_model (int specIndex, char *value, int len) |
| Get the selected spectrometer's model. More... | |
| int | wp_get_serial_number (int specIndex, char *value, int len) |
| Get the selected spectrometer's serial number. More... | |
| int | wp_get_wavelengths (int specIndex, double *wavelengths, int len) |
| Get the selected spectrometer's calibrated wavelength x-axis in nanometers. More... | |
| int | wp_get_wavelengths_float (int specIndex, float *wavelengths, int len) |
| Get the selected spectrometer's calibrated wavelength x-axis in nanometers as float. More... | |
| int | wp_get_wavenumbers (int specIndex, double *wavenumbers, int len) |
| Get the selected spectrometer's calibrated x-axis in wavenumbers (1/cm) More... | |
| int | wp_get_wavenumbers_float (int specIndex, float *wavenumbers, int len) |
| Get the selected spectrometer's calibrated x-axis in wavenumbers (1/cm) as float. More... | |
| int | wp_get_spectrum (int specIndex, double *spectrum, int len) |
| Read one spectrum from the selected spectrometer. More... | |
| int | wp_get_spectrum_float (int specIndex, float *spectrum, int len) |
| Read one spectrum from the selected spectrometer as float. More... | |
| int | wp_get_eeprom_field_count (int specIndex) |
| This is provided so the caller can correctly size the 'names' and 'values' arrays for a call to wp_get_eeprom(). More... | |
| int | wp_get_eeprom_field_name (int specIndex, int index, char *value, int len) |
| Obtain the nth ordered EEPROM field name. More... | |
| int | wp_get_eeprom (int specIndex, const char **names, const char **values, int len) |
| Read a table of all EEPROM fields, as strings. More... | |
| int | wp_get_eeprom_field (int specIndex, const char *name, char *valueOut, int len) |
| Read one stringified EEPROM field by name. More... | |
| int | wp_get_eeprom_page (int specIndex, int page, uint8_t *buf, int len) |
| int | wp_set_logfile_path (const char *pathname, int len) |
| Sets a pathname for WasatchVCPP to write a debug logfile. More... | |
| int | wp_set_log_level (int level) |
| Sets driver log level. More... | |
| int | wp_log_debug (const char *msg, int len) |
| Allows calling code (and wrappers) to inject lines into the library's log. More... | |
| int | wp_set_integration_time_ms (int specIndex, unsigned long ms) |
| Set the spectrometer's integration time in milliseconds. More... | |
| int | wp_set_laser_enable (int specIndex, int value) |
| Turns the laser on or off. More... | |
| int | wp_set_laser_power_perc (int specIndex, float percent) |
| Sets laser power as a percentage of max power. More... | |
| int | wp_set_laser_power_mW (int specIndex, float percent) |
| Sets laser power as a mW value. More... | |
| int | wp_set_detector_gain (int specIndex, float value) |
| Set detector gain. More... | |
| int | wp_set_detector_gain_odd (int specIndex, float value) |
| On InGaAs spectrometers, configures the gain for odd-numbered pixels. More... | |
| int | wp_set_detector_offset (int specIndex, int value) |
| Set detector offset. More... | |
| int | wp_set_detector_offset_odd (int specIndex, int value) |
| On InGaAs spectrometers, configures the offset for odd-numbered pixels. More... | |
| int | wp_set_detector_tec_enable (int specIndex, int value) |
| Turn the detector TEC on or off. More... | |
| int | wp_set_detector_tec_setpoint_deg_c (int specIndex, int value) |
| Set the detector TEC setpoint. More... | |
| int | wp_set_high_gain_mode_enable (int specIndex, int value) |
| Enable or disable "high gain" mode on InGaAs detectors. More... | |
| int | wp_get_firmware_version (int specIndex, char *value, int len) |
| Get the firmware version of the microcontroller (FX2 or ARM). More... | |
| int | wp_get_fpga_version (int specIndex, char *value, int len) |
| Get the version of the FPGA. More... | |
| float | wp_get_detector_temperature_deg_c (int specIndex) |
| Get the detector temperature. More... | |
| long | wp_get_integration_time_ms (int specIndex) |
| Get the curent integration time. More... | |
| int | wp_get_laser_enable (int specIndex) |
| Reports whether laser is currently enabled (firing, or configured to do so). More... | |
| float | wp_get_detector_gain (int specIndex) |
| Get the current detector gain (on InGaAs, even pixels only). More... | |
| float | wp_get_detector_gain_odd (int specIndex) |
| Get the current detector gain for odd InGaAs pixels. More... | |
| int | wp_get_detector_offset (int specIndex) |
| Get the current detector offset (on InGaAs, even pixels only). More... | |
| int | wp_get_detector_offset_odd (int specIndex) |
| Get the current detector offset for odd InGaAs pixels. More... | |
| int | wp_get_detector_tec_enable (int specIndex) |
| Reports whether the detector TEC is enabled. More... | |
| int | wp_get_detector_tec_setpoint_deg_c (int specIndex) |
| Get the current detector TEC setpoint in degrees Celsius. More... | |
| int | wp_get_high_gain_mode_enable (int specIndex) |
| Reports whether "high-gain mode" is currently enabled on InGaAs detectors. More... | |
| int | wp_cancel_operation (int specIndex, int blocking) |
| If an acquisition is currently in progress, cancel it. More... | |
| int | wp_set_max_timeout_ms (int specIndex, int maxTimeoutMS) |
| Configure the maximum internal timeout when waiting on blocking USB operations. More... | |
| int | wp_get_max_timeout_ms (int specIndex) |
| Get the maximum internal timeout when waiting on blocking USB operations. More... | |
| int | wp_write_eeprom_page (int specIndex, int pageIndex, unsigned char *data, int dataLen) |
| int | wp_send_control_msg (int specIndex, unsigned char bRequest, unsigned int wValue, unsigned int wIndex, unsigned char *data, int len) |
| Provide direct access to writing spectrometer opcodes via USB setup packets (endpoint 0 control. More... | |
| int | wp_read_control_msg (int specIndex, unsigned char bRequest, unsigned int wIndex, unsigned char *data, int len) |
| Provide direct access to reading spectrometer opcodes via USB setup packets (endpoint 0 control. More... | |
| int | wp_get_vignetted_spectrum_length (int specIndex) |
| int | wp_get_raman_intensity_factors (int specIndex, double *factors, int factorsLen) |
| int | wp_apply_raman_intensity_factors (int specIndex, double *spectrum, int spectrum_len, double *factors, int factors_len, int start_pixel, int end_pixel) |
| int | wp_has_srm_calibration (int specIndex) |
Variables | |
| Driver * | driver = Driver::getInstance() |
Implementation of the flattened C API exported by WasatchVCPP.dll.
This file implements the "C" interface to the WasatchVCPP library and DLL which is defined in WasatchCPP.h.
This file is the one and only place where the WasatchVCPP::Driver Singleton is actually instantiated (meaning it probably doesn't actually have to be a Singleton...)
| int exportString | ( | string | s, |
| char * | buf, | ||
| int | len | ||
| ) |
copy a std::string to a C string
| s | (Input) a populated std::string |
| buf | (Output) the destination where the string is to be copied |
| len | (Input) allocated size of 'buf' |
| int wp_cancel_operation | ( | int | specIndex, |
| int | blocking | ||
| ) |
If an acquisition is currently in progress, cancel it.
Note that while this function will return instantly, the current operation is guaranteed to complete within the currently configured "maximum timeout" as set through wp_set_max_timeout_ms.
| specIndex | (Input) which spectrometer |
| block | (Input) whether the function should block until the current operation completes (0 for non-blocking, non-zero for blocking) |
| int wp_close_all_spectrometers | ( | ) |
Closes all connected spectrometers.
| int wp_close_spectrometer | ( | int | specIndex | ) |
Closes the specified spectrometer.
| specIndex | (Input) which spectrometer |
| void wp_destroy_driver | ( | ) |
Permanently releases all objects from memory.
It is recommended to close and restart the application be after calling this function, before wp_open_all_spectrometers can be called again.
| float wp_get_detector_gain | ( | int | specIndex | ) |
Get the current detector gain (on InGaAs, even pixels only).
| specIndex | (Input) which spectrometer |
| float wp_get_detector_gain_odd | ( | int | specIndex | ) |
Get the current detector gain for odd InGaAs pixels.
| specIndex | (Input) which spectrometer |
| int wp_get_detector_offset | ( | int | specIndex | ) |
Get the current detector offset (on InGaAs, even pixels only).
| specIndex | (Input) which spectrometer |
| int wp_get_detector_offset_odd | ( | int | specIndex | ) |
Get the current detector offset for odd InGaAs pixels.
| specIndex | (Input) which spectrometer |
| int wp_get_detector_tec_enable | ( | int | specIndex | ) |
Reports whether the detector TEC is enabled.
| specIndex | (Input) which spectrometer |
| int wp_get_detector_tec_setpoint_deg_c | ( | int | specIndex | ) |
Get the current detector TEC setpoint in degrees Celsius.
| specIndex | (Input) which spectrometer |
| float wp_get_detector_temperature_deg_c | ( | int | specIndex | ) |
Get the detector temperature.
| specIndex | (Input) which spectrometer |
| int wp_get_eeprom | ( | int | specIndex, |
| const char ** | names, | ||
| const char ** | values, | ||
| int | len | ||
| ) |
Read a table of all EEPROM fields, as strings.
This is provided as a fast-and-simple way to expose the entire EEPROM to the caller in one function call. It would be nice if we could return the actual EEPROM object with all the fields parsed into native types, but you can't send objects across the ABI. It would be nice if we could send a std::map of name-value pairs, but you can't send templates across the ABI. So we get...this.
Note this doesn't actually copy any data...all it does is copy the current pointer location of each EEPROM field name and stringified value from the EEPROM::stringified map. Currently, there is no use-case where those strings are changed after the spectrometer is instantiated, partly because we're not yet supporting "EEPROM write".
Therefore these character pointers SHOULD be valid until the spectrometers are closed and their EEPROM objects destroyed. However, it would probably be a good idea for calling code to make copies of these values if it wants to persist them. (This is what WasatchVCPP::Proxy does, instantiating each field into a new map<string, string> immediately after calling this function.)
A "full" API implementation could probably include native-type accessors (and settors!) for every field in the EEPROM; I've already added such "convenience accessors" for pixels, model and serialNumber due to their relative importance when testing spectroscopy applications. However, that's a lot of typing and testing, and this will do for now.
| specIndex | (Input) which spectrometer |
| names | (Output) a pre-allocated array of character pointers to hold field names |
| values | (Output) a pre-allocated array of character pointers to hold field values |
| len | (Input) number of elements in names and values arrays |
| int wp_get_eeprom_field | ( | int | specIndex, |
| const char * | name, | ||
| char * | value, | ||
| int | len | ||
| ) |
Read one stringified EEPROM field by name.
If you don't want to call wp_get_eeprom and only want one or two fields and you already know their names, this can be easier than reading the whole table.
| specIndex | (Input) which spectrometer |
| name | (Input) case-insensitive name of the desired EEPROM field |
| value | (Output) a pre-allocated character array to hold the value |
| len | (Input) length of pre-allocated array |
| int wp_get_eeprom_field_count | ( | int | specIndex | ) |
This is provided so the caller can correctly size the 'names' and 'values' arrays for a call to wp_get_eeprom().
| specIndex | (Input) which spectrometer |
| int wp_get_eeprom_field_name | ( | int | specIndex, |
| int | index, | ||
| char * | value, | ||
| int | len | ||
| ) |
Obtain the nth ordered EEPROM field name.
| specIndex | (Input) which spectrometer |
| index | (Input) which field (1...wp_get_eeprom_field_count) |
| value | (Output) allocated character buffer of 'len' bytes |
| len | (Input) size of allocated value buffer |
| int wp_get_firmware_version | ( | int | specIndex, |
| char * | value, | ||
| int | len | ||
| ) |
Get the firmware version of the microcontroller (FX2 or ARM).
| specIndex | (Input) which spectrometer |
| value | (Output) pre-allocated character array |
| len | (Input) allocated size (should be 16+) |
| int wp_get_fpga_version | ( | int | specIndex, |
| char * | value, | ||
| int | len | ||
| ) |
Get the version of the FPGA.
| specIndex | (Input) which spectrometer |
| value | (Output) pre-allocated character array |
| len | (Input) allocated size (should be 16+) |
| int wp_get_high_gain_mode_enable | ( | int | specIndex | ) |
Reports whether "high-gain mode" is currently enabled on InGaAs detectors.
| specIndex | (Input) which spectrometer |
| long wp_get_integration_time_ms | ( | int | specIndex | ) |
Get the curent integration time.
| specIndex | (Input) which spectrometer |
| int wp_get_laser_enable | ( | int | specIndex | ) |
Reports whether laser is currently enabled (firing, or configured to do so).
| specIndex | (Input) which spectrometer |
| int wp_get_library_version | ( | char * | value, |
| int | len | ||
| ) |
Obtains the version number of the WasatchVCPP library itself.
| value | (Output) pre-allocated string to receive the value |
| len | (Input) length of allocated buffer (16 recommended) |
| int wp_get_max_timeout_ms | ( | int | specIndex | ) |
Get the maximum internal timeout when waiting on blocking USB operations.
| specIndex | (Input) which spectrometer |
| int wp_get_model | ( | int | specIndex, |
| char * | value, | ||
| int | len | ||
| ) |
Get the selected spectrometer's model.
| specIndex | (Input) which spectrometer |
| value | (Output) pre-allocated buffer of 'len' bytes (33 recommended) |
| len | (Input) allocated length of 'value' |
| int wp_get_number_of_spectrometers | ( | ) |
Returns number of spectrometers previously opened.
Assumes that wp_open_all_spectrometers has already been called. Does not open or re-open anything; no state is changed. (convenience function)
| int wp_get_pixels | ( | int | specIndex | ) |
Returns the number of pixels in the selected spectrometer.o.
This is critical for correctly sizing arrays sent to other functions like get_spectrum or get_wavelengths.
| specIndex | (Input) which spectrometer |
| int wp_get_serial_number | ( | int | specIndex, |
| char * | value, | ||
| int | len | ||
| ) |
Get the selected spectrometer's serial number.
| value | (Output) pre-allocated buffer of 'len' bytes (33 recommended) |
| len | (Input) allocated length of 'value' |
| int wp_get_spectrum | ( | int | specIndex, |
| double * | spectrum, | ||
| int | len | ||
| ) |
Read one spectrum from the selected spectrometer.
This sends an "ACQUIRE" command, waits for "integration time" to pass, then performs a blocking read from the bulk endpoint.
| specIndex | (Input) which spectrometer |
| spectrum | (Output) pre-allocated buffer of 'len' doubles |
| len | (Input) allocated length of 'xAxis' (should match 'pixels') |
| int wp_get_spectrum_float | ( | int | specIndex, |
| float * | spectrum, | ||
| int | len | ||
| ) |
Read one spectrum from the selected spectrometer as float.
This sends an "ACQUIRE" command, waits for "integration time" to pass, then performs a blocking read from the bulk endpoint.
| specIndex | (Input) which spectrometer |
| spectrum | (Output) pre-allocated buffer of 'len' floats |
| len | (Input) allocated length of 'xAxis' (should match 'pixels') |
| int wp_get_wavelengths | ( | int | specIndex, |
| double * | wavelengths, | ||
| int | len | ||
| ) |
Get the selected spectrometer's calibrated wavelength x-axis in nanometers.
| specIndex | (Input) which spectrometer |
| wavelengths | (Output) pre-allocated buffer of 'len' doubles |
| len | (Input) allocated length of 'wavelengths' (should match 'pixels') |
| int wp_get_wavelengths_float | ( | int | specIndex, |
| float * | wavelengths, | ||
| int | len | ||
| ) |
Get the selected spectrometer's calibrated wavelength x-axis in nanometers as float.
| specIndex | (Input) which spectrometer |
| wavelengths | (Output) pre-allocated buffer of 'len' floats |
| len | (Input) allocated length of 'wavelengths' (should match 'pixels') |
| int wp_get_wavenumbers | ( | int | specIndex, |
| double * | wavenumbers, | ||
| int | len | ||
| ) |
Get the selected spectrometer's calibrated x-axis in wavenumbers (1/cm)
| specIndex | (Input) which spectrometer |
| wavenumbers | (Output) pre-allocated buffer of 'len' doubles |
| len | (Input) allocated length of 'wavenumbers' (should match 'pixels') |
| int wp_get_wavenumbers_float | ( | int | specIndex, |
| float * | wavenumbers, | ||
| int | len | ||
| ) |
Get the selected spectrometer's calibrated x-axis in wavenumbers (1/cm) as float.
| specIndex | (Input) which spectrometer |
| wavenumbers | (Output) pre-allocated buffer of 'len' floats |
| len | (Input) allocated length of 'wavenumbers' (should match 'pixels') |
| int wp_log_debug | ( | const char * | msg, |
| int | len | ||
| ) |
Allows calling code (and wrappers) to inject lines into the library's log.
| msg | (Input) null-terminated C string |
| len | (Input) length of string |
| int wp_open_all_spectrometers | ( | ) |
Connects to and initializes all enumerated USB spectrometers.
This is normally the first function called against the library. It is normally called only once per application session.
It does quite a lot of work:
After calling this function, the driver is fully configured and ready to control all connected spectrometers.
| int wp_read_control_msg | ( | int | specIndex, |
| unsigned char | bRequest, | ||
| unsigned int | wIndex, | ||
| unsigned char * | data, | ||
| int | len | ||
| ) |
Provide direct access to reading spectrometer opcodes via USB setup packets (endpoint 0 control.
If a particular spectrometer feature documented in ENG-0001 is not yet suppoted by the library, or if you need to test an experimental / un- released feature against beta firmware, you can do so with this function.
| specIndex | (Input) which spectrometer |
| bRequest | (Input) control packet request (uint8_t) |
| wIndex | (Input) control packet wIndex (uint16_t) |
| data | (Output) pre-allocated buffer to hold response (uint8_t[]) |
| len | (Input) number of bytes to read (data should be sized accordingly) |
| int wp_send_control_msg | ( | int | specIndex, |
| unsigned char | bRequest, | ||
| unsigned int | wValue, | ||
| unsigned int | wIndex, | ||
| unsigned char * | data, | ||
| int | len | ||
| ) |
Provide direct access to writing spectrometer opcodes via USB setup packets (endpoint 0 control.
If a particular spectrometer feature documented in ENG-0001 is not yet suppoted by the library, or if you need to test an experimental / un- released feature against beta firmware, you can do so with this function.
| specIndex | (Input) which spectrometer |
| bRequest | (Input) control packet request (uint8_t) |
| wValue | (Input) control packet wValue (uint16_t) |
| wIndex | (Input) control packet wIndex (uint16_t) |
| data | (Input) control packet payload (uint8_t[]) |
| len | (Input) length of control packet payload |
| int wp_set_detector_gain | ( | int | specIndex, |
| float | value | ||
| ) |
Set detector gain.
This should not be done casually by the user; detector gain is normally optimized for a given detector series, and rarely varies significantly from component to component. In the event that detector gain calibration is required, it is done at the factory, and the calibrated value is stored in the EEPROM ("detectorGain").
There is a lot which can be said about this attribute, which may be fleshed-out here at a later date. The internal data format is somewhat odd, essentially a signed bfloat16 (see WasatchNET documentation on FunkyFloat). For historical reasons, many spectrometers are tuned to a default gain of 1.9 (0x01e6). It is a valid question why the calibrated gain is stored on the spectrometer (in the EEPROM) yet needs to be applied from software over USB.
| specIndex | (Input) which spectrometer |
| value | (Input) desired gain (e.g. 1.9) |
| int wp_set_detector_gain_odd | ( | int | specIndex, |
| float | value | ||
| ) |
On InGaAs spectrometers, configures the gain for odd-numbered pixels.
Hamamatsu InGaAs detectors use two interleaved arrays of photodiodes, where one array controls even-numbered pixels and the other array controls the odd-numbered. This means that with regard to gain and noise characteristics, all even pixels are electrically related, and all odd pixels are electrically related, but the two sets may behave differently from one another. Therefore, NIR spectrometers support independent gain and offset calibration for the two pixels sets.
| specIndex | (Input) which spectrometer |
| value | (Input) desired gain (positive or negative) |
| int wp_set_detector_offset | ( | int | specIndex, |
| int | value | ||
| ) |
Set detector offset.
| specIndex | (Input) which spectrometer |
| value | (Input) desired offset (positive or negative) |
| int wp_set_detector_offset_odd | ( | int | specIndex, |
| int | value | ||
| ) |
On InGaAs spectrometers, configures the offset for odd-numbered pixels.
| specIndex | (Input) which spectrometer |
| value | (Input) desired offset (positive or negative) |
| int wp_set_detector_tec_enable | ( | int | specIndex, |
| int | value | ||
| ) |
Turn the detector TEC on or off.
| specIndex | (Input) which spectrometer |
| value | (Input) zero for off, non-zero for on |
| int wp_set_detector_tec_setpoint_deg_c | ( | int | specIndex, |
| int | value | ||
| ) |
Set the detector TEC setpoint.
| specIndex | (Input) which spectrometer |
| value | (Input) desired temperature in degrees Celsius |
| int wp_set_high_gain_mode_enable | ( | int | specIndex, |
| int | value | ||
| ) |
Enable or disable "high gain" mode on InGaAs detectors.
| specIndex | (Input) which spectrometer |
| value | (Input) zero to disable, non-zero to enable |
| int wp_set_integration_time_ms | ( | int | specIndex, |
| unsigned long | ms | ||
| ) |
Set the spectrometer's integration time in milliseconds.
| specIndex | (Input) which spectrometer |
| int wp_set_laser_enable | ( | int | specIndex, |
| int | value | ||
| ) |
Turns the laser on or off.
| specIndex | (Input) which spectrometer |
| value | (Input) whether laser should be off (zero) or on (non-zero) |
| int wp_set_laser_power_mW | ( | int | specIndex, |
| float | power | ||
| ) |
Sets laser power as a mW value.
| power | (Input) mW power to set laser |
| int wp_set_laser_power_perc | ( | int | specIndex, |
| float | percent | ||
| ) |
Sets laser power as a percentage of max power.
| percent | (Input) percent of max power |
| int wp_set_log_level | ( | int | level | ) |
Sets driver log level.
| level | (Input) one of the WP_LOG_LEVEL macros |
| int wp_set_logfile_path | ( | const char * | pathname, |
| int | len | ||
| ) |
Sets a pathname for WasatchVCPP to write a debug logfile.
| pathname | (Input) a valid pathname (need not exist, will be overwritten if found) |
| len | (Input) length of pathname |
| int wp_set_max_timeout_ms | ( | int | specIndex, |
| int | maxTimeoutMS | ||
| ) |
Configure the maximum internal timeout when waiting on blocking USB operations.
Note this value can be less than integration time. If a configured integration time is longer than the maximum timeout, then the "wait" on the requested spectrum will be performed through a series of individual reads, each no longer than the configured maximum timeout.
That is, if maxTimeoutMS is 1000, and a 5sec integration is requested, The library will loop through five 1sec blocking reads before the spectrum is expected to return. (The library will internally wait even longer than that, to account for USB latency and other timing delays, but no individual blocking read will wait longer than the configured maximum.)
This value also represents the longest that wp_cancel_operation(true) should block.
This function essentially configures the maximum window before a call to wp_cancel_operation will be expected to take effect.
| specIndex | (Input) which spectrometer |
| maxTimeoutMS | (Input) maximum timeout in milliseconds (default 1000; probably should not be < 200) |