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
> fp=libpointer('tag_ooi_fam_param',OOI_FAM_PARAM)
use libstruct instead of libpointer?
-quo
I have tried to use
fp=libsruct('tag_ooi_fam_param',OOI_FAM_PARAM)
It gives the same error message
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
I have the same problem, did you find a solution??
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
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
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
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,
Poul-Erik <p...@ihk.dk> wrote in message <ef060...@webx.raydaftYaTP>...
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
Kind regards
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>...