NI Home
Cart Cart | Help
Hello Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI
You are here: 
NI Home > NI Developer Zone > NI Discussion Forums


Reply
Member
opcode_torule
Posts: 5
0 Kudos

DAQmxReadAnalogF64

[ Edited ]

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

Active Participant
snowpunter
Posts: 272
0 Kudos

Re: DAQmxReadAnalogF64

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

 

 

CTA, CLD, MTFBWY
By using this web site, you accept the Terms of Use for this web site. Please read these Terms of Use carefully before using any part of this site. Please go here for information on ni.com's copyright infringement policy.
My Profile | Privacy | Legal | Contact NI © 2011 National Instruments Corporation. All rights reserved.    |    E-Mail this Page E-Mail this Page