Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmxReadAnalogF64

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

0 Kudos
Message 1 of 2
(2,896 Views)

Take at look at the examples located in the picture. It will greatly assist you.

 

 

CTA, CLA, MTFBWY
0 Kudos
Message 2 of 2
(2,875 Views)