/* UL call demonstrated: ulAInLoadQueue() Purpose: Set up the queue with available ranges and input modes Demonstration: Initialize and load the queue Steps: 1. Call ulGetDaqDeviceInventory() to get the list of available DAQ devices 2. Call ulCreateDaqDevice() to to get a handle for the first DAQ device 3. Verify the DAQ device has an analog input subsystem 4. Verify the analog input subsystem has a hardware pacer 5. Get the supported ranges 6. Get the supported queue types 7. Setup the queue structure array 8. Call ulConnectDaqDevice() to establish a UL connection to the DAQ device 9. Call ulAInLoadQueue() to load the queue 10. Call ulAInScan() to start the scan of A/D input channels 11. Call ulAiScanStatus to check the status of the background operation 12. Display the data for each channel 13. Call ulAinScanStop() to stop the background operation 14. Call ulDisconnectDaqDevice and ulReleaseDaqDevice() before exiting the process */ #include #include #include "uldaq.h" #include "utility.h" #define MAX_DEV_COUNT 100 #define MAX_RANGE_COUNT 8 #define MAX_STR_LENGTH 64 #define MAX_SCAN_OPTIONS_LENGTH 256 #define MAX_QUEUE_SIZE 32 // arbitrary limit for the size for the queue int main(void) { int descriptorIndex = 0; DaqDeviceDescriptor devDescriptors[MAX_DEV_COUNT]; DaqDeviceInterface interfaceType = ANY_IFC; DaqDeviceHandle daqDeviceHandle = 0; unsigned int numDevs = MAX_DEV_COUNT; // when using the queue, the lowChan, highChan, inputMode, and range // parameters are ignored since they are specified in queueArray int lowChan = 0; int highChan = 3; AiInputMode inputMode; Range range; // set some variables that are used to acquire data int samplesPerChannel = 10000; double rate = 1000; ScanOption scanOptions = (ScanOption) (SO_DEFAULTIO | SO_CONTINUOUS); AInScanFlag flags = AINSCAN_FF_DEFAULT; Range ranges[MAX_RANGE_COUNT]; int hasAI = 0; int hasPacer = 0; int numRanges = 0; int numberOfChannels = 0; int queueTypes; int index = 0; char rangeStr[MAX_STR_LENGTH]; char inputModeStr[MAX_STR_LENGTH]; char scanOptionsStr[MAX_SCAN_OPTIONS_LENGTH]; int chanCount = 0; double *buffer = NULL; AiQueueElement queueArray[MAX_QUEUE_SIZE]; UlError err = ERR_NO_ERROR; int __attribute__ ((unused))ret; char c; int i = 0; // Get descriptors for all of the available DAQ devices err = ulGetDaqDeviceInventory(interfaceType, devDescriptors, &numDevs); if(err != ERR_NO_ERROR) goto end; // verify at least one DAQ device is detected if (numDevs == 0) { printf("No DAQ devices are connected\n"); goto end; } printf("Found %d DAQ device(s)\n", numDevs); for (i = 0; i < (int) numDevs; i++) printf(" %s: (%s)\n", devDescriptors[i].productName, devDescriptors[i].uniqueId); // get a handle to the DAQ device associated with the first descriptor daqDeviceHandle = ulCreateDaqDevice(devDescriptors[descriptorIndex]); if (daqDeviceHandle == 0) { printf ("\nUnable to create a handle to the specified DAQ device\n"); goto end;; } // verify the specified DAQ device supports analog input err = getDevInfoHasAi(daqDeviceHandle, &hasAI); if (!hasAI) { printf("\nThe specified DAQ device does not support analog input\n"); goto end; } // verify the specified device supports hardware pacing for analog input err = getAiInfoHasPacer(daqDeviceHandle, &hasPacer); if (!hasPacer) { printf("\nThe specified DAQ device does not support hardware paced analog input\n"); goto end; } // get the queue types err = getAiInfoQueueTypes(daqDeviceHandle, &queueTypes); // get the first supported analog input mode err = getAiInfoFirstSupportedInputMode(daqDeviceHandle, &numberOfChannels, &inputMode, inputModeStr); if (highChan >= numberOfChannels) highChan = numberOfChannels - 1; chanCount = highChan - lowChan + 1; // does the device support a queue if (queueTypes == 0) { printf("\nThe specified DAQ device does not support a queue\n"); goto end; } // get the analog input ranges err = getAiInfoRanges(daqDeviceHandle, inputMode, &numRanges, ranges); // assign each channel in the queue an input mode (SE/DIFF) and a range ... if // multiple ranges are supported, we will cycle through them and repeat ranges if the // number of channels exceeds the number of ranges // // this block of code could be used to set other queue elements such as the input mode // and channel list for (i=0; i