4.1.3 - Analog Inputs [U3 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 31/199. x1 parameter is not used and can be set to 0
LJ_ioGET_AIN_DIFF //Specify negative channel in x1.
The following are special channels, used with the get/put config IOTypes, to configure parameters that apply to all analog inputs:
LJ_chAIN_RESOLUTION //QuickSample enabled if TRUE.
LJ_chAIN_SETTLING_TIME //LongSettling enabled if TRUE.
LJ_chAIN_BINARY
Following is example pseudocode to read analog inputs:
//Execute the pin_configuration_reset IOType so that all
//pin assignments are in the factory default condition.
//The ePut function is used, which combines the add/go/get.
ePut (lngHandle, LJ_ioPIN_CONFIGURATION_RESET, 0, 0, 0);
//Configure FIO1, FIO2, and FIO6 as analog, all others as
//digital (see Section 4.3.2). b01000110 = 0x46 = d70.
//The ePut function is used, which combines the add/go/get.
ePut (lngHandle, LJ_ioPUT_ANALOG_ENABLE_PORT, 0, 70, 16);
//Now, an add/go/get block to execute multiple requests.
//Request a single-ended read from AIN2.
AddRequest (lngHandle, LJ_ioGET_AIN, 2, 0, 0, 0);
//Request a differential read of AIN1-AIN6.
AddRequest (lngHandle, LJ_ioGET_AIN_DIFF, 1, 0, 6, 0);
//Request a differential read of AIN1-Vref.
AddRequest (lngHandle, LJ_ioGET_AIN_DIFF, 1, 0, 30, 0);
//Request a single-ended read of AIN1.
AddRequest (lngHandle, LJ_ioGET_AIN_DIFF, 1, 0,199, 0);
//Request a read of AIN1 using the special 0-3.6 volt range.
AddRequest (lngHandle, LJ_ioGET_AIN_DIFF, 1, 0, 32, 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 AIN2 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 AIN1-AIN6 voltage.
GetNextResult (lngHandle, 0, 0, &dblValue, 0, 0);
//Get the AIN1-Vref voltage.
GetNextResult (lngHandle, 0, 0, &dblValue, 0, 0);
//Get the AIN1 voltage.
GetNextResult (lngHandle, 0, 0, &dblValue, 0, 0);
//Get the AIN1 voltage (special 0-3.6 volt range).
GetNextResult (lngHandle, 0, 0, &dblValue, 0, 0);