4.1.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 5.2.5.2
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);