OceanHDX spectrometers source code and test programs

"The key to happiness is self-delusion."
On this page:

Introduction

So I couldn't get either of the official libraries provided by Ocean Optics to work on Linux on my recent OceanHDX spectrometers. The Java library (OmniDriver) was hard to install, overkill and wouldn't recognize my gear. And neither would the open source C++ library (SeaBreeze). After digging around the (long and complex) code without success I spent a few days rolling my own. It's a single C file with a bunch of simple function calls. It's only for Linux, but there are only a few lines to change to get it to run on Windows.

Features: most low level functions are implemented including getting raw spectra with metadata; those missing are easy to add. There's a Makefile and 3 test programs, simply run them with -h for help.

Implemented: getting the correct wavelengths, correction for non-linearity, averaging, integration. Separate dark-taking or auto-integration are optional in the test programs.

Limitations: only one spectrometer at a time. Only TCP or USB connection (no serial, but that wouldn't be hard to add). I've tested it on the following models: OCEAN-HDX-UV-VIS, OCEAN-HDX-VIS-NIR, OCEAN-HDX-XR. I don't know about other models besides the HDX but since the low level commands are mostly the same, my guess is that it would work with minimal changes.

Not implemented: electronic dark removal, delay (easy to add), strobe, Wifi, buffering, GPIO, sensors, SPI, I2C.... But look at the code, some might be partially implemented already.

Category:
ANSI C (Windows, Unix...), LabWindows/CVI
2019/11/28
First version
2019/11/28
C_Ocean_HDX source code published on gitlab and open-sourced with GPLv3.


[Spectro.png]
Spectrum visualization with SpectroVisu.

Visualization

I wrote a quick and dirty LabWindows/CVI program to do a visualization of a single scan, as saved by the previous program. It's in the same project file, but you need the LabWindows compiler (for Windows or Linux). It opens files saved by OceanHDX or OceanHDX_QuickTest, but not the RAW files containing multiple scans.



Spectrometer calibration

Along with the C library to control the spectrometer, there is an executable that allows for calibration of the spectrometer, provided you have an Ocean Optics HG-1 or HG-2 calibration source (if you have another type of calibration source, just look at the code and add the list of peaks in there, there's an option for that). The program is OceanHDX_Calib.c, found on the same gitlab project and here is an example of use where I run it twice to verify the alignment of the peaks (denoted in white, and they should be in the middle of the table). Outliers are eliminated manually on the 1st run by giving their indices.

So here's the procedure: you run it first with a fairly large SR window (4nm by default). If you see most of the peaks (in white) line up nicely, then fine, just remove the outliers to improve precision and commit the results to memory. If you don't see any peaks lining up, try with a wider SR. Then do a second run with a narrow SR, a high average and integration to minimize noise in order to improve the precision of your 1st measurement.


Non-relevant note about colors (in consoles, not in spectros...)

In Linux it does not seem possible to copy text from a KDE Konsole (or any other kind of terminal) and keep the colors when you paste them somewhere else. But there's a solution by piping to aha, a program that converts the terminal's colors to HTML. I used the following command to copy the text above while keeping the program interactive:

$ make && ./OceanHDX_Calib -auto -A100 -F -SR=1 | tee >(aha >outfile.html)