Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Matlab interface to Spectrometer dll

140 views
Skip to first unread message

Poul-Erik

unread,
May 15, 2005, 7:11:57 PM5/15/05
to
Hi
I am trying to call an oceanoptics spectrometer from matlab using the
supplied dll with the spectrometer. Using this dll you dont call one
spectrometer at the time you are actually calling 4 spectrometers at
the time.
I only have one spectrometer and are therefore using the Flexible
acquistion method which basicaly means that you can set the
induvidual properties of each spectrometer.
I belive that my problem is that libstruct in matlab does not support
vectors or matrix? If anyone now a workaround I would be delighted.

Here is the data structure, function description, my code and the
errormessage

C-structure
//////////////////////////////////////////////////////////////////////
/////////////
//// OOI_FAM_PARAM structure for Flexible acquisition mode
//////////////////////////////////////////////////////////////////////
/////////////
typedef struct tag_ooi_fam_param
{
short cmd; // command, use CMD_ constants
short fdc[4]; // flash delay (in msec) array
WORD dsf[4]; // sampling frequency (kHz - S1000, msec - S2000)
array
short boxcar[4]; // boxcar smoothing width array
short average[4]; // samples to average array
short chan_ena[4]; // spectrometer channel enabled array
short scan_dark[4]; // scan dark array
short correct_dark[4]; // correct for electrical dark signal array
short extrig[4]; // external trigger mode array
short upper4chan; // flag true if want data from S2000 channels
4-7
short error[4]; // return value array for each OOI_DoScan call
float data[4][2048]; // an array of 4 channels x 2048 elements
BOOL UseUSecIntegrationTime;
DWORD USecIntegrationTime[4];
} OOI_FAM_PARAM;

Function description:
OOI_Flexible_Acquisition
short OOI_Flexible_Acquisition(OOI_FAM_PARAM* fp)

Parameter
Use

fp
Pointer to an OOI_FAM_PARAM structure. All members of the
OOI_FAM_PARAM structure must be filled prior to calling this function

Return Value:

This function returns ER_NOERROR if the function was successful, or
one of the ER_ constants if the function was not successful. Also,
the error array of the OOI_FAM_PARAM structure contains the error
values for each enabled spectrometer channel.

This function is used when you need to have different acquisition
parameters (integration time, number of scans to average, etc.) for
each spectrometer channel. All of the parameters necessary to
complete a set of spectral acquisitions are contained within the
OOI_FAM_PARAM structure.


My code:

path = 'C:\Program Files\Ocean Optics\OOIWinIP\Drivers';
addpath(path);
path='C:\Program Files\Ocean Optics\OOIWinIP\Include';
addpath(path);
if ~libisloaded('OOIDrv32')
loadlibrary('OOIDrv32.dll','OOIDrv32.h')
end
N=calllib('OOIDrv32','OOI_GetNumberOfPixels');%Number of CCD pixels
channels = 1:N;%1 channel per pixel
OOI_FAM_PARAM.cmd=[0];
OOI_FAM_PARAM.fdc=zeros(1,4);
OOI_FAM_PARAM.dsf=[100,0,0,0];
OOI_FAM_PARAM.boxcar=zeros(1,4);
OOI_FAM_PARAM.average=zeros(1,4);
OOI_FAM_PARAM.chan_ena=[1,0,0,0];
OOI_FAM_PARAM.scan_dark=zeros(1,4);
OOI_FAM_PARAM.correct_dark=zeros(1,4);
OOI_FAM_PARAM.extrig=zeros(1,4);
OOI_FAM_PARAM.upper4chan=zeros(1,4);
OOI_FAM_PARAM.error=zeros(1,4);
OOI_FAM_PARAM.data=zeros(4,N);
OOI_FAM_PARAM.UseUSecIntegrationTime=0;
OOI_FAM_PARAM.USecIntegrationTime=zeros(1,4);
fp=libpointer('tag_ooi_fam_param',OOI_FAM_PARAM)
calllib('OOIDrv32','OOI_Flexible_Acquisition',fp);

Error:
??? A field does not match one in the struct.

Error in ==> libpointer at 18
ptr=lib.pointer(varargin{:});

Error in ==> HR4000_GetSignal at 146
fp=libpointer('tag_ooi_fam_param',OOI_FAM_PARAM)

Poul-Erik

quo

unread,
May 16, 2005, 12:04:50 PM5/16/05
to
Not real sure because I try to avoid messing with libpointer and
libstruct, but shouldn't this line:

> fp=libpointer('tag_ooi_fam_param',OOI_FAM_PARAM)

use libstruct instead of libpointer?

-quo

Poul-Erik

unread,
May 16, 2005, 2:57:12 PM5/16/05
to
Hi quo

I have tried to use
fp=libsruct('tag_ooi_fam_param',OOI_FAM_PARAM)

It gives the same error message

Poul-Erik

Simon

unread,
May 20, 2005, 3:28:23 AM5/20/05
to
Hi Poul-Erik

You are correct: libstruct() ONLY supports scalar structures. So you cannot assign the chan_ena[] and other parameters. You can get around this by using the OOI_DoScan_Array function in the OOIWinIP DLL.

However, this leads to another problem. The argument for OOI_DoScan_Array requires two pointers: one to an array of initialization parameters, and the other to an array where the spectral data can be written to. I have tried to accomplish this with the following code:

param=[0 0 1 0 1 1 0 0 0 0 0 0 0] %(or similar)

data=zeros(3469,4) %3469 pixels will be returned

ptr2param=libpointer('doublePtr', param)
ptr2data=libpointer('doublePtr', data)

calllib('OOIDRV32', 'OOI_DoScan_Array', ptr2param, ptr2data)

This code seems somewhat redundant, in that I shouldn't need to create the pointers, as Matlab is supposed to implicitly create them. However, the code still causes a segmentation violation! Here is the method prototype for OOI_DoScan_Array, as given by libfunctionview:

[int16, voidPtr, voidPtr] OOI_DoScan_Array [voidPtr, VoidPtr]

Any ideas about how to prevent the segmentation violation??

thanks!
-Simon

Marina

unread,
Jul 21, 2005, 5:18:29 PM7/21/05
to
Hello Poul-Erik,

I have the same problem, did you find a solution??

Marina

Poul-Erik

unread,
Jul 28, 2005, 8:40:10 AM7/28/05
to
Hi Marina

I have a solution for USB2000 spectrometer but it does not work with
my HR4000 spectrometer. What kind of spectrometer do you have?

Poul-Erik

Marina

unread,
Aug 8, 2005, 1:59:27 PM8/8/05
to
Hi Poul-Erik,

I have S2000 with ADC500 (I think). But I will be happy to see your
solution for USB200, maybe it will give me a clue what to do next.

Thank you for your help,
Marina

Poul-Erik

unread,
Aug 9, 2005, 3:46:19 PM8/9/05
to
It belive the code works with minor modification on a S2000
spectrometer which is fairly old

Here is a copy of my test code
%set path to driver
sti = 'C:\Program Files\Ocean Optics\OOIWinIP\Drivers';
addpath(sti);
sti = 'C:\Program Files\Ocean Optics\OOIWinIP\Include';
addpath(sti);

loadlibrary('OOIDrv32.dll','OOIDrv32.h')

%% You can only use libstruct on scalar structures.
%% Hence FULLPARM = libstruct('FULLPARM'); is a no no

%% calllib('OOIDrv32','OOI_GetSpectrometerType') gives Segmentation
%% violation

calllib('OOIDrv32','OOI_GetNumberOfPixels')

N = 2048;%number of channels on USB 2000 spectrometer
channels = 1:N;

% short OOI_DoScan_Array(short* sht, float* flt)
% Parameter Use
%
% sht
% Pointer to an array of short integers representing acquisition
% parameters / SCANPARM Equivalent
%
% flt
% Pointer to an array of floating point values for storage of
spectral data
TRUE = 1;
FALSE = 0;

scanparm = zeros(1,16);
scanparm(1+0) = 0; % no specific command CMD_NONE; % cmd
scanparm(1+1) = 0; % fdc
scanparm(1+2) = 100; % dsf
scanparm(1+3) = 1; % boxcar
scanparm(1+4) = 1; % average
scanparm(1+5) = TRUE; % chan_ena[0] - Master
scanparm(1+6) = FALSE; % chan_ena[1]
scanparm(1+7) = FALSE; % chan_ena[2]
scanparm(1+8) = FALSE; % chan_ena[3]
scanparm(1+9) = FALSE; % scan_dark
scanparm(1+10) = FALSE; % correct_dark
scanparm(1+11) = 0; % extrig
scanparm(1+12) = FALSE; % upper4chan

pSp = libpointer('int32Ptr', scanparm);
get(pSp)

%spectrum = zeros(1,N); % N = 2048 throws a Segmentation violation
hence we use 8192 ;-)
% Why? Maybe 4 spectrums - Yes
% See SCANPARM Declares the data buffers to contain data from the
driver.
% The array is declared as 4 (for 4 channels) by 2048 (for 2048
pixels).

spectrum = zeros(1,8192); works with USB2000

pSpectrum = libpointer('singlePtr', spectrum);
get(pSpectrum)

%subplot(2,1,1);
GraphSignalA = plot(spectrum(channels),'g-');
axis([1 N 0 4096]);%Max 4096 counts per channel
xlabel('Channel');
ylabel('Signal');
set(GraphSignalA,'EraseMode','normal');

for j =1:1000
erno = calllib('OOIDrv32','OOI_DoScan_Array_Long',pSp,pSpectrum);
if (erno)
erno
error('see Driver error codes in OOIDRV32.H');
end
spectrum = get(pSpectrum, 'Value');

title(strcat('Spectrum :', num2str(j)));
set(GraphSignalA,'XData',channels,'YData',spectrum(channels));
drawnow
end

unloadlibrary('OOIDrv32');

Hope it works out for you.

Please send me a copy of you code when it works.

Poul-Erik

Marina

unread,
Sep 6, 2005, 9:35:37 AM9/6/05
to
Hello Poul-Erik,

Thank you for your answer. I made a fast try with this code on S200,
but it didn't work. Unfortunatelly I had no time for and luck with
troubleshooting. I will send you an update in case I get any positive
results in the future.

Thanks again for your help,

Eneas Nicolas

unread,
Aug 1, 2007, 3:16:13 PM8/1/07
to
Hello I saw in the Web of matlab that you this developing a soft to use the HR4000 with matlab, ceria to know if it could make it work, since in these days I am about to to buy a HR4000, thanks

Poul-Erik <p...@ihk.dk> wrote in message <ef060...@webx.raydaftYaTP>...

Lenny

unread,
Aug 29, 2010, 2:16:04 PM8/29/10
to
Hi!


I created a vb6 program that interfaces ocean optics spectrometers (USB4000, Maya Pro etc.) with Octave/Matlab using a shell pipe.

Let me know if anyone needs this.

- Len

Fernando Carreño

unread,
Oct 7, 2010, 3:01:06 PM10/7/10
to
"Lenny " <lcsa...@ucdavis.edu> wrote in message <i5e854$ftf$1...@fred.mathworks.com>...
It would be great to get such interface to access the USB spectrometers. Should it work with USB2000 like machines?

Kind regards

Juan

unread,
May 17, 2011, 8:55:04 PM5/17/11
to
Hello,

I would love to give your vb6 program a try.

Thanks

Juan

"Lenny " <lcsa...@ucdavis.edu> wrote in message <i5e854$ftf$1...@fred.mathworks.com>...

ben07...@gmail.com

unread,
Apr 27, 2012, 11:40:52 AM4/27/12
to Lenny
Hi Len,

Can you please send my the program?

Thanks,
Ben

Ruben

unread,
Dec 16, 2012, 7:05:16 AM12/16/12
to
"Lenny " <lcsa...@ucdavis.edu> wrote in message <i5e854$ftf$1...@fred.mathworks.com>...
Hi Lenny,

I would like to try you program. Could you send me the program?

Thanks in advance

RUBEN

jean...@gmail.com

unread,
Oct 10, 2013, 8:26:06 AM10/10/13
to
Hello,

I know this post is a little bit old, but I would enjoy if you could share your code with me ;-)

Best,

Jean


0 new messages