Chinese (Simplified)EnglishFrenchItalianPortugueseSpanish
|

Ocean Optics
Worldwide Headquarters
Largo, Florida, USA

+1 727-733-2447

[email protected]

Sales, Service
& Support Facility
Duiven, The Netherlands

EU:
+31 26-319-0500
FR:
+33 442-386-588

[email protected]

Ocean Optics GmbH Sales,
Service & Support Facility
Ostfildern, Germany

+49 711-34-16-96-0

[email protected]

Sales Support
for the
United Kingdom

+44 1865-819922

[email protected]

Sales, Service
& Support Facilities
Shanghai, PRC – Beijing, PRC

+86 21-6295-6600

[email protected]

Close
Home > Frequently Asked Questions > Software > OmniDriver and SPAM > Controlling USB spectrometers from OmniDriver and MATLAB

Controlling USB spectrometers from OmniDriver and MATLAB

Want to use MathWorks MATLAB to directly control your USB spectrometers, reading and post-processing spectra from .m files? No worries, MATLAB and OmniDriver are old friends.

OmniDriver includes a file in OOI_HOME called OmniDriver.jar, which provides the complete class structure of OmniDriver to any program which can utilize Java JAR files — including MATLAB! Calling the OmniDriver Wrapper can be as simple as this:

>> javaaddpath('C:\Program Files\Ocean Optics\OmniDriver\OOI_HOME\OmniDriver.jar');
>> wrapper = com.oceanoptics.omnidriver.api.wrapper.Wrapper();
>> wrapper.openAllSpectrometers();
>> spectrum = wrapper.getSpectrum(0);
>> wavelengths = wrapper.getWavelengths(0);
>> plot(wavelengths, spectrum);

MATLAB-MacOSX

Feel free to explore the full Java Wrapper API as documented here:

One note: MATLAB may complain about having trouble finding the native USB device drivers…something like this:

java.lang.ExceptionInInitializerError
            at com.oceanoptics.uniusb.USB.<init> (USB.java:20)
            at com.oceanoptics.omnidriver.features.USBImpl.<init> (USBImpl.java:62)
                 (blah blah blah)
            at com.oceanoptics.omnidriver.api.wrapper.Wrapper.openAllSpectrometers
                 (Wrapper.java:507)
Caused by: java.lang.RuntimeException: Failed to load any native library for USB.  
                 Tried base filenames: NatUSB_64, NatUSB_32, NatUSB
            at com.oceanoptics.uniusb.UniUSB.<clinit>(UniUSB.java:75)

What this means is that MATLAB’s JNI (Java Native Interface) can’t find the .DLL (or .so or .dylib for Linux and Mac) “native libraries” which OmniDriver uses to talk over USB on each operating system. And unfortunately, there is no way to dynamically “re-point” MATLAB to look at a new path after MATLAB launches (this is not the same as CLASSPATH, nor is it the same as LD_LIBRARY_PATH).

Fortunately, you can follow a quick and simple procedure to update MATLAB’s JNI path between MATLAB sessions:

  1. Launch MATLAB
  2. Type “mr = matlabroot” (this should display the path to matlabroot on your installation)
  3. Close MATLAB
  4. Open matlabroot/toolbox/local/librarypath.txt
    1. (you may have to manually open Accessories -> WordPad from the Start Menu by right-clicking “Run As Administrator”)
  5. Add path to OOI_HOME on your installation (e.g. C:\Program Files\Ocean Optics\OmniDriver\OOI_HOME)
  6. Relaunch MATLAB

To learn more about matlabroot, see these links (valid at writing):

To time operations in MATLAB, just use this:

% initialize spectrometer
wrapper = com.oceanoptics.omnidriver.api.wrapper.Wrapper();
wrapper.openAllSpectrometers();

% set integration time to 1 millisec (1000 microsec)
wrapper.setIntegrationTime(0, 1000);

% take 10,000 spectra
time_start = datestr(now,'dd-mm-yyyy HH:MM:SS.FFF');
for i = 1:10000
  spectrum = wrapper.getSpectrum(0);
end
time_end = datestr(now,'dd-mm-yyyy HH:MM:SS.FFF');

% display the time it took
display(time_start);
display(time_end);
  • Was this answer helpful?
  • Yes   No
OmniDriver

OmniDriver

Cross-Platform Full-Featured Device Driver
SPAM

SPAM

Spectral Processing And Math Library