To show how to read a single analog input value using an MCC data acquisition device and various software platforms.
Data acquisition system developers who need to occasionally read an AI channel, and seek to understand its implementation approach in various software environments.
Analog input DAQ devices are usually touted for their high-speed continuous AI sampling prowess. But when used in this manner, the amount of data generated can be overwhelming to sift through and store. To facilitate transferring such large amounts of data over the system bus, data is usually queued up into large packets or blocks, which could delay the availability of a particular data point. To complement the high speed multi-channel AI scanning, MCC DAQ devices also support the other end of the spectrum – reading a single AI value from one AI channel.
For USB DAQ, the time required to read a single value from one AI channel varies by DAQ model, but is generally from 1 ms to 5 ms. When you make that reading request, your program waits for the resultant data point from the DAQ device. This is referred to as polling, or software paced reading, since no pacer clock or hardware memory queue is utilized.
Often the user will set up a software timer (or timed loop) since a new voltage reading is often needed over and over. Other tasks, such as sending a value to a DAQ output channel based on the voltage input value, can also reside in the loop. Such a loop is often referred to as a control loop, and as such requires timely input readings. No software timer or looping is shown in this document, for the sake of simplicity.
As the number of AI channels in your application and/or the sample rate increases, this single-read approach may not meet your overall throughput needs. Also, if your application does not need “access” to each and every sample as it becomes available, such as in the case where you will process data in larger arrays or analyze data only at the end of the run, then you should consider the waveform/array capture scenario.
Independent of the software platform, the following information must be specified for each analog input read:
And the following two pieces of information are returned:
- Voltage reading
- Error code
The examples below show how to sample a single AI reading using the Universal Library™, UL for Android™, NI LabVIEW™, and DASYLab®.
The following example shows how to sample an AI value using the Universal library (UL) and Visual Basic:
Channel = 0 ’Specify channel # 0
Range = MccDaq.Range.Bip10Volts ’Specify the ±10 V input range
ULStat = DaqBoard.VIn (Channel, Range, DataValue, Options)
The voltage reading is returned as the DataValue, while the error code is returned as the value of ULStat.
UL for Android
The following example shows how to sample an AI value using UL for Android and Java.
// Establish connection to the DAQ device
// Read AI channel 0
AiDaqDevice mAiDevice = mDaqDevice.getAiDev();
aInValue = mAiDevice.aIn(0, ChannelMode.SINGLE_ENDED, Range.BIP10VOLTS,
The voltage reading is returned to aInValue.
The following example shows how to sample an AI value using LabVIEW. The wiring diagram below shows the pertinent VIs and settings. The first channel (AiO) of hardware device #0 is asked to return one measurement value within the expected range of -10 V to +10 V.
Non-programmers who need to take occasional readings should consider the popular package DASYLab. The following example worksheet shows an Analog Input module with its output wired to a Digital Meter display module. The voltage reading is presented in the meter display.
Double-clicking on the Analog Input module allows you to access menus where you can select the N samples mode.
Here we specify 1 for N (the number of samples.)
Please contact Measurement Computing Corporation if you have any questions or if you would like any further information.
Additional TechTips are available on our Data Acquisition Technical Articles web page.