/* UL call demonstrated: ulDaqInScan() Purpose: Performs a continuous scan of the available analog, digital, and/or counter input subsystems Demonstration: Displays the analog, digital, and counter input data on the specified channels 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 DAQ input subsystem 4. Get the channel types supported by the DAQ input subsystem 5. Call ulConnectDaqDevice() to establish a UL connection to the DAQ device 6. Configure the available analog, digital, and counter channels 7. Call ulDaqInScan() to start the scan 8. Call ulDaqInScanStatus to check the status of the background operation 9. Display the data for each channel 10. Call ulDaqInScanStop() to stop the background operation 11. Call ulDisconnectDaqDevice and ulReleaseDaqDevice() before exiting the process */ #include #include #include "uldaq.h" #include "utility.h" // prototypes UlError ConfigureAnalogInputChannels(int numberOfChannels, Range range, DaqInChanDescriptor* descriptors, int* scanDesriptorIndex); UlError ConfigureDigitalInputChannel(DaqDeviceHandle daqDeviceHandle, DaqInChanDescriptor* descriptors, int* scanDesriptorIndex); UlError ConfigureCounterInputChannels(DaqDeviceHandle daqDeviceHandle, int numberOfChannels, DaqInChanDescriptor* descriptors, int* scanDesriptorIndex); #define MAX_DEV_COUNT 100 #define MAX_STR_LENGTH 64 #define MAX_SCAN_OPTIONS_LENGTH 256 int main(void) { int descriptorIndex = 0; AiInputMode inputMode = AI_SINGLE_ENDED; DaqDeviceDescriptor devDescriptors[MAX_DEV_COUNT]; DaqDeviceInterface interfaceType = ANY_IFC; DaqDeviceHandle daqDeviceHandle = 0; unsigned int numDevs = MAX_DEV_COUNT; int samplesPerChannel = 10000; double rate = 1000; Range range = BIP10VOLTS; ScanOption scanOptions = (ScanOption) (SO_DEFAULTIO | SO_CONTINUOUS); DaqInScanFlag flags = DAQINSCAN_FF_DEFAULT; int numberOfAiChannels = 3; int numberOfScanChannels = 3; int hasDAQI = 0; int index = 0; int chanTypesMask = 0; char inputModeStr[MAX_STR_LENGTH]; char scanOptionsStr[MAX_SCAN_OPTIONS_LENGTH]; char daqiChannelTypeStr[MAX_SCAN_OPTIONS_LENGTH]; char rangeStr[MAX_SCAN_OPTIONS_LENGTH]; DaqInChanDescriptor scanDescriptors[numberOfScanChannels]; int scanDescriptorIndex = 0; double* buffer = NULL; UlError err = ERR_NO_ERROR; int i = 0; int __attribute__((unused)) ret; char c; // 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 device is detected\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 device supports analog input err = getDevInfoHasDaqi(daqDeviceHandle, &hasDAQI); if (!hasDAQI) { printf("\nThe specified DAQ device does not support DAQ input\n"); goto end; } printf("\nConnecting to device %s - please wait ...\n", devDescriptors[descriptorIndex].devString); // establish a connection to the DAQ device err = ulConnectDaqDevice(daqDeviceHandle); if (err != ERR_NO_ERROR) goto end; // get the channel types supported by the DAQ input subsystem err = getDaqiChannelTypes(daqDeviceHandle, &chanTypesMask); if (chanTypesMask == 0) { printf("\nDaqInScan is not supported by the specified DAQ device\n"); goto end; } // configure the analog channels if (chanTypesMask & DAQI_ANALOG_SE) { // get the first supported analog input mode err = getAiInfoFirstSupportedInputMode(daqDeviceHandle, &numberOfAiChannels, &inputMode, inputModeStr); // get the first supported input range getAiInfoFirstSupportedRange(daqDeviceHandle, inputMode, &range, rangeStr); err = ConfigureAnalogInputChannels(1, range, scanDescriptors, &scanDescriptorIndex); } else { // no analog channels so decrement the count numberOfScanChannels--; } // configure the digital channels if ((chanTypesMask & DAQI_DIGITAL) && err == ERR_NO_ERROR) { err = ConfigureDigitalInputChannel(daqDeviceHandle, scanDescriptors, &scanDescriptorIndex); } else { // no digital channels so decrement the count numberOfScanChannels--; } // configure the counter channels if ((chanTypesMask & DAQI_CTR32) && err == ERR_NO_ERROR) { err = ConfigureCounterInputChannels(daqDeviceHandle, 1, scanDescriptors, &scanDescriptorIndex); } else { // no counter channels so decrement the count numberOfScanChannels--; } // allocate a buffer to receive the data buffer = (double*) malloc(numberOfScanChannels * samplesPerChannel * sizeof(double)); if(buffer == 0) { printf("\nOut of memory, unable to create scan buffer\n"); goto end; } ConvertScanOptionsToString(scanOptions, scanOptionsStr); printf("\n%s ready\n", devDescriptors[descriptorIndex].devString); printf(" Function demonstrated: ulDaqInScan()\n"); printf(" Number of scan channels: %d\n", numberOfScanChannels); for (i=0; i