4.3.3 - Analog Inputs [U6 Datasheet] | LabJack
« Close

Datasheets and User Guides

App Notes

Software & Driver


4.3.3 - Analog Inputs [U6 Datasheet]

The AIN can be read using AddRequest, Go/GoOne, and GetResult/GetNextResult. eGet or eAddGoGet could also be used.

The IOTypes to retrieve a command/response analog input reading are:

LJ_ioGET_AIN       //Single-ended.  Negative channel is fixed as 0/15/199. x1 is not used and can be set to 0
LJ_ioGET_AIN_DIFF  //Specify negative channel in x1.

Differential channels are adjacent even/odd pairs only, such as AIN2-AIN3. Thus the positive channel must be even and the negative channel must be +1. The Windows UD driver has different IOTypes for single-ended or differential reads, but the differential IOType can always be used as a negative channel (x1 parameter) of 0/15/199 equates to a single-ended reading. When using a Mux80 the even/odd channel pairing no longer applies, please refer to the “Using Differential Analog Inputs with the MUX80” section on the Mux80 datasheet page for additional details. The following are IOTypes used to configure the input range of a particular analog input channel:

LJ_ioPUT_AIN_RANGE    // Range and Gain are synonymous

In addition to specifying the channel number, the following range (i.e. gain) constants are passed in the value parameter when doing a request with the AIN range IOType:

LJ_rgBIP10V     // +/- 10V, i.e. Gain=x1
LJ_rgBIP1V      // +/- 1V, i.e. Gain=x10
LJ_rgBIPP1V     // +/- 0.1V, i.e. Gain=x100
LJ_rgBIPP01V    // +/- 0.01V, i.e. Gain=x1000

The following are special channels, used with the get/put config IOTypes, to configure parameters that apply to all analog inputs:

LJ_chAIN_RESOLUTION     //0=default, 1-8=high-speed ADC, 9-12=high-res ADC
LJ_chAIN_SETTLING_TIME  //0-9 where 0=Auto, see Section
LJ_chAIN_BINARY         //0=disable 1=enable

Following is example pseudocode to read analog inputs:

//Configure all analog inputs for max resolution.  Like most
//settings, this will apply to all further measurements until
//the parameter is changed or the DLL unloaded.
AddRequest (lngHandle, LJ_ioPUT_CONFIG, LJ_chAIN_RESOLUTION, 12, 0, 0);

//Configure AIN1 for +/- 10 volt range.
AddRequest (lngHandle, LJ_ioPUT_AIN_RANGE, 1, LJ_rgBIP10V, 0, 0);

//Configure AIN2 for +/- 1 volt range.  This applies to any
//reading, single-ended or differential, where the positive
//channel is AIN2.
AddRequest (lngHandle, LJ_ioPUT_AIN_RANGE, 2, LJ_rgBIP1V, 0, 0);

//Request a single-ended read from AIN1.
AddRequest (lngHandle, LJ_ioGET_AIN, 1, 0, 0, 0);

//Request a differential read of AIN2-AIN3.
AddRequest (lngHandle, LJ_ioGET_AIN_DIFF, 2, 0, 3, 0);

//Request a single-ended read of AIN2.  Here we use the DIFF
//IOType, but pass x1=199 which does a single-ended measurement.
AddRequest (lngHandle, LJ_ioGET_AIN_DIFF, 2, 0, 199, 0);

//Execute the requests.
GoOne (lngHandle);

//Since multiple requests were made with the same IOType
//and Channel, and only x1 was different, GetFirst/GetNext
//must be used to retrieve the results.  The simple
//GetResult function does not use the x1 parameter and
//thus there is no way to specify which result is desired.
//Rather than specifying the IOType and Channel of the
//result to be read, the GetFirst/GetNext functions retrieve
//the results in order.  Normally, GetFirst/GetNext are best
//used in a loop, but here they are simply called in succession.

//Retrieve AIN1 voltage.  GetFirstResult returns the IOType,
//Channel, Value, x1, and UserData from the first request.
//In this example we are just retrieving the results in order
//and Value is the only parameter we need.
GetFirstResult (lngHandle, 0, 0, &dblValue, 0, 0);

//Get the AIN2-AIN3 voltage.
GetNextResult (lngHandle, 0, 0, &dblValue, 0, 0);

//Get the AIN2.
GetNextResult (lngHandle, 0, 0, &dblValue, 0, 0);


Is the LJ_ioGET_AIN_DIFF IOType implemented for the U6, or is it restricted to the U3 as indicated in the LabJackUD.h file?  Cheers.

It does work for the U6 also.  The comment in the header file is outdated.

If you do not specify the range for a given AIN what does it default to when using the U6-Pro? Also if it is desirable to explicitly set the range is there a way to do it for all AINs?

The default is +/-10V.

At this time there is no single write to set the range of all AIN (you will have to loop through all channels), but added something to our to-do list.


is it possible to use different resolutions for different AI channels in one Go()? I would like to read one channel in the full resolution, then a few channels in a lower one for speed. It seems to me that when using the UD drivers the resolution for all channels is set by the last call that sets the resolution before the Go().



Looking at the low-level Feedback function and the AIN24 IOType, I see that resolution is passed with each reading request, so I'm thinking the following will work the way you want when using Add/Go/Get:

AddRequest (lngHandle, LJ_ioPUT_CONFIG, LJ_chAIN_RESOLUTION, 12, 0, 0);
AddRequest (lngHandle, LJ_ioGET_AIN, 1, 0, 0, 0);
AddRequest (lngHandle, LJ_ioPUT_CONFIG, LJ_chAIN_RESOLUTION, 1, 0, 0);
AddRequest (lngHandle, LJ_ioGET_AIN, 2, 0, 0, 0);
AddRequest (lngHandle, LJ_ioPUT_CONFIG, LJ_chAIN_RESOLUTION, 1, 0, 0);
AddRequest (lngHandle, LJ_ioGET_AIN, 3, 0, 0, 0);

I will have a UD driver expert confirm this.

The UD Driver does process commands in the order they are given (as the other post says) but it also processes them in groups.  In this case the calls to change the resolution are all processed, with the last being the most current, and then the analog inputs are read (in the order they are specified) with that resolution.  While the U6 does allow for channels to have different resolutions, the UD driver was not built with that kind of flexibility when it was originally designed for the UE9 (in the UE9 all channels use the same resolution).  It could potentially be added but that would require some customization.

The easiest fix for this would be to use eAin() to read each channel at a different resolution.  That would be less efficient in terms of communication, but would give you that flexibility, and would probably work for most applications. You could also use the LabJackUD's lower level read/write functionality to send a feedback packet directly.

The T7 and LabJackM library were designed to work that way, and individual resolutions/ranges can be specified on a per channel basis in an easy fashion.  If that is a requirement of yours you might look at it as an option.  I believe we also have (or are close to) a firmware version for the U6 that works with the LabJackM library which would give this kind of flexibility.  If you'd like more info on that you can email us at [email protected].


Thank you for the in-depth response! I'm glad to have the LabJack. Your post confirms my expectation - for now it is OK for me to basically do 2 Go()s to collect the low-res and hi-res data. I'll stay tuned for the updated firmware.




How can I print (or get to a variable) the range value of a channel?

I am working with DAQfactory and try to write in the command line something like:

? eGet(u6ID,LJ_ioGET_AIN_RANGE, 48,LJ_rgBIPP01V,0)


I am trying to read an analog input that comes straight from DAC1 into EIO5 which is declared as analog input, but when trying to read the value of the DAC, it appears it reads it one cycle after. As for Example:


0.2 0.99

1 0.23

1.2 1

What can i do to fix these?

EIO5 is digital only on the U6.  Perhaps you mean AIN5?

With DAC1 jumpered to AIN5, if you set DAC1 and then in the same packet immediately read AIN5, it might happen too fast.  From Appendix A you can see that the time constant (tau) of DAC1 is typically about 300us, so that means it would take about 300us for DAC1 to change 63% of the way from the old value to the new value.  1 tau = 63%, 2 tau = 86%, 3 tau = 95%, 4 tau = 98%, and 5 tau = 99%.  In your add/go/get block, consider adding a PUT_WAIT request to add delay between the DAC request and AIN request.

In some applications, it makes sense to more sense to do AIN5-DAC1 (rather than DAC1-AIN5).  So you do your feedback calculations to determine the new setpoint, read the feedback voltage, set the new setpoint, calculate a new setpoint, read the feedback voltage, set the new setpoint, ..., and so on.