06-24-2012 11:52 AM - edited 06-24-2012 11:53 AM
Dear friends,
at the moment I am trying to use the DLL functins to read analog data from my SCXI 1122 over PCI 6220 with MATLAB. I don't use the DAQ Toolbox,because this Toolbox does not support my hardware in a full way yet. As reference I use the good documentated NI-DAQmx C Reference Help.
My problem is understanding the DAQmxReadAnalogF64 Function. It seems, that the data is stored into the 'int32 *sampsPerChanRead and not into 'readArray[]'. When I run my programm I get no data ın readArray stored, because it is a pointer (Error message in MATLAB) but I get some data in the
'*sampsPerChanRead' variable. (Some Noise Values. Scale: -5mv to 5mv). In my example code the 'readArray[]' varible is: readarray and the pointer: ptr_readarray. The *sampsPerChanRead' is readsample and ptr_readsample. Here is the example code:
As I understand right, the sampsPerChanRead only gives the number how many samples are read, ısnt ıt ? So it must be an Integer ? But the values I get seems to be the data I read from the AI0 Channel (for example I connected a J Type Thermocouple). The values are something with * 10^-5V
%% Read the analog input channel
%-------------- NI-DAQmx C Reference Help ---------------------------------
% Functin to read an analog input channel
%
% int32 DAQmxReadAnalogF64 (
% TaskHandle taskHandle,
% int32 numSampsPerChan,
% float64 timeout,
% bool32 fillMode,
% float64 readArray[],
% uInt32 arraySizeInSamps,
% int32 *sampsPerChanRead,
% bool32 *reserved);
%--------------------------------------------------------------------------
readtimeout=10; %timeout in seconds for the read function
% Create the buffer where the data will be stored and a pointer to this
% buffer
readarray=ones(1,samples);
ptr_readarray=libpointer('doublePtr',readarray);
%Create a buffer where number of read samples are stored and a pointer to
%this buffer
readsamples=1;
ptr_readsamples=libpointer('int32Ptr',readsamples);
%Create an empty buffer and a pointer to this buffer for the 'reserved'
%argument. This argument is reserved for future use and should be passed
%as NULL.
empty=[];
ptr_empty=libpointer('uint32Ptr',empty);
arraySizeInSamps=1*samples;
[err, readarray, readsamples, empty] = ...
calllib(libalias,'DAQmxReadAnalogF64',taskhandle,samples,...
readtimeout,DAQmx_Val_GroupByScanNumber,ptr_readarray,...
arraySizeInSamps,ptr_readsamples,ptr_empty);
if(err==0)
disp('The data has been read successfully!');
elseif(err<0)
disp('An error has occured ! Data has not been read');
%disp(strcat('Error code: ',num2str(err)));
DAQmxCheckError(libalias,err)
end
sampleperiod=1/samplerate;
timevec=sampleperiod:sampleperiod:acquiretime;
disp([timevec readarray]);
%plot(timevec,readarray);
%*************************************************************************%
Thank you !
best regards,
opcode_torule
06-25-2012 05:04 PM
Take at look at the examples located in the picture. It will greatly assist you.