From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Acquire Analog I/P & display in indicator

Hi all, Im new to CVI & hopefully can get some help.

 

How do I acquire analog input from a DAQ and display all Analog channel 0-31 in indicator?

I've seen most examples display result on a graph.

 

For example,

....

....

DAQmxReadAnalogF64 (taskHandle, samplesToReadPerChannel, 10.0,
         DAQmx_Val_GroupByChannel, data,
         numChannels*samplesToReadPerChannel, &actualSamplesRead, 0);

 

Where to extract each channel sample and display all in each indicator?


Thanks alot!

0 Kudos
Message 1 of 6
(4,064 Views)

A good way to approach daq programming is to start from an existing example: you can find those installed on your PC by using the example finder by using Help >> Find examples... menu function; there you can search among locally installed samples and samples on NI site.

On your PC you should have these examples installed: is this code abstract coming from one of them? 

 

In any case, you can find the sampled data in your 'data' array, and since you choose DAQmx_Val_GroupByChannel as tge grouping order all samples by one channel are stored together in the array. That is, coming from index 0 in the array you'll find actualSamplesRead samples from first channel, then the same number of samples from the second channel and so on.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 6
(4,055 Views)

Hi thanks for reply.

 

I have looked through the examples... still figuring out some part.

 

So i suppose index 0 contain channel 1, index 2 - channel 2 and so on...

 

How do I loop through actualSamplesRead to get the reading for each channel? Can you show me some example?

 

Appreciate lots!

0 Kudos
Message 3 of 6
(4,048 Views)

Actually content and organization of data array depends on several parameters; specifically (from function help):

 

numSampsPerChan int32 The number of samples, per channel, to read. The default value of -1 (DAQmx_Val_Auto) reads all available samples. If readArray does not contain enough space, this function returns as many samples as fit in readArray.

NI-DAQmx determines how many samples to read based on whether the task acquires samples continuously or acquires a finite number of samples.

If the task acquires samples continuously and you set this parameter to -1, this function reads all the samples currently available in the buffer.

If the task acquires a finite number of samples and you set this parameter to -1, the function waits for the task to acquire all requested samples, then reads those samples. If you set the Read All Available Samples property to TRUE, the function reads the samples currently available in the buffer and does not wait for the task to acquire all requested samples.
fillMode bool32 Specifies whether or not the samples are interleaved.
Value   Description
DAQmx_Val_GroupByChannel   Group by channel (non-interleaved)
DAQmx_Val_GroupByScanNumber   Group by scan number (interleaved)

 

That is:

  • If you acquire 1 samples per channel, then the fill mode is not relevant and samples from various channel are store sequentially in data array.
  • If you acquire more than one sample, then fillMode parameter is relevant as to how samples are stored: see the linked page on interleaving.

Measures from one channel are simply a subset of the whole array: you can extract the relevant portion by looping into the array or using functions like Copy1D (for non interleaved grouping) or Decimate (for interleaved data)

 



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 6
(4,040 Views)

Hi there,

 

thanks for the useful information.

 

just another question... I have seen examples:

 

/*********************************************/
  // DAQmx Write Code
  /*********************************************/
  DAQmxErrChk (DAQmxWriteAnalogF64(taskHandle,1,1,10.0,DAQmx_Val_GroupByChannel,&data,NULL,NULL));

 }

 

Error:
 SetWaitCursor(0);
 if( DAQmxFailed(error) )
  DAQmxGetExtendedErrorInfo(errBuff,2048);
 if( taskHandle!=0 ) {
  /*********************************************/
  // DAQmx Stop Code
  /*********************************************/
  DAQmxStopTask(taskHandle);
  DAQmxClearTask(taskHandle);
 }
 if( DAQmxFailed(error) )
  MessagePopup("DAQmx Error",errBuff);
 return 0;
}

 

So what does DAQmxErrChk do? whats the difference between having this and not?

Any detail explaination?

 

Thanks...

0 Kudos
Message 5 of 6
(4,021 Views)

Hi Adriano,

an useful trick in CVI is that after having succesfully compiled and linked a project you can then right click on a keyword in the code and use "Go to definition" item to go to its definition (alternatively press Ctrl+I accelerator which is the same).

 

When you do this on DAQmxErrChk you should be directed to this macro definition:

#define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else

As you see, this macro simply tests function return code (via DAQmxFailed macro, which you can discover the same way) and jumps to a label named Error in case of errors after having stored the error code for future reference. An int variable named 'error' and the label must exists in every function into which you are using the macro.

What to do in case of errors depends on what you were doing when they arised: in this case as you can see the hardware is stopped and a warning is issued in case an error was found in the code. It's up to you, in case you want to reuse this macro in your own code, to take the proper actions depending on your environment and the resources you are using.

 

I use extensively this paradigm extending it to other cases of error: you may find useful reading my contribution here.

 



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 6 of 6
(4,014 Views)