03-26-2014 10:57 AM - edited 03-26-2014 11:17 AM
Hello,
I'm trying to measure with K-thermocouples with the NI USB-9213 that is hooked to a NI cDAQ-9174. I'm measuring multiple channels continiously. However when I pass a certain amount of a channels (more than 8 channels simultaniously) it returns erroneous values at some indices of the acquired data array. Usually its 2292 degrees Celsius while it should be around 20 - 25 degrees Celsius. When I measure with 8 channels it works flawlessly. I call the function that I use to measure with:
contSampleThermocouple("Dev2/ai0:11", 12, 1, 5, 0.0, 300.0, "test");
The code of the function is given below.
#include <stdio.h> #include "NIDAQmx.h" #include "mylib.h" #define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else int32 CVICALLBACK EveryNCallbackThermocouple(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData); int32 CVICALLBACK DoneCallbackThermocouple(TaskHandle taskHandle, int32 status, void *callbackData); // Global variables int numberOfChannelsGlobalThermocouple, measurementCounterThermocouple = 0; float64 sampleRateGlobalThermocouple, sampsPerChanGlobalThermocouple; char *fileNameGlobal; int contSampleThermocouple(char *channels, int numberOfChannels, int sampleRate, int sampsPerChan, float64 minVal, float64 maxVal, char *fileName) { int32 error = 0; TaskHandle taskHandle = 0; char errBuff[2048] = { '\0' }; // Set globial variables numberOfChannelsGlobalThermocouple = numberOfChannels; sampleRateGlobalThermocouple = sampleRate; sampsPerChanGlobalThermocouple = sampsPerChan; fileNameGlobal = fileName; /*********************************************/ // DAQmx Configure Code /*********************************************/ DAQmxErrChk(DAQmxCreateTask("", &taskHandle)); DAQmxErrChk(DAQmxCreateAIThrmcplChan(taskHandle, channels, "", minVal, maxVal, DAQmx_Val_DegC, DAQmx_Val_K_Type_TC, DAQmx_Val_BuiltIn, 25.0, "")); DAQmxErrChk(DAQmxSetChanAttribute(taskHandle, "", DAQmx_AI_AutoZeroMode, DAQmx_Val_EverySample)); DAQmxErrChk(DAQmxCfgSampClkTiming(taskHandle, "", (float64)sampleRate, DAQmx_Val_Rising, DAQmx_Val_ContSamps, (float64)sampsPerChan)); DAQmxErrChk(DAQmxRegisterEveryNSamplesEvent(taskHandle, DAQmx_Val_Acquired_Into_Buffer, (uInt32)sampsPerChan, 0, EveryNCallbackThermocouple, NULL)); DAQmxErrChk(DAQmxRegisterDoneEvent(taskHandle, 0, DoneCallbackThermocouple, NULL)); /*********************************************/ // DAQmx Start Code /*********************************************/ DAQmxErrChk(DAQmxStartTask(taskHandle)); printf("Acquiring samples continuously. Press Enter to interrupt\n"); getchar(); Error: if (DAQmxFailed(error)) DAQmxGetExtendedErrorInfo(errBuff, 2048); if (taskHandle != 0) { /*********************************************/ // DAQmx Stop Code /*********************************************/ DAQmxStopTask(taskHandle); DAQmxClearTask(taskHandle); } if (DAQmxFailed(error)) printf("DAQmx Error: %s\n", errBuff); printf("End of program, press Enter key to quit\n"); getchar(); return 0; } int32 CVICALLBACK EveryNCallbackThermocouple(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData) { int32 error = 0; char errBuff[2048] = { '\0' }; static int totalRead = 0; int32 read = 0; float64 data[60]; // Fill data array with -1000 for (int i = 0; i < 60; i++) { data[i] = -1000; } /*********************************************/ // DAQmx Read Code /*********************************************/ DAQmxErrChk(DAQmxReadAnalogF64(taskHandle, -1, 10.0, DAQmx_Val_GroupByScanNumber, data, 60, &read, NULL)); if (read > 0) { writeToCsv(data, fileNameGlobal, "temperature", "AI", "a", numberOfChannelsGlobalThermocouple, sampleRateGlobalThermocouple, sampsPerChanGlobalThermocouple, measurementCounterThermocouple); measurementCounterThermocouple++; printf("Acquired %d samples. Total %d\r", read, totalRead += read); fflush(stdout); } Error: if (DAQmxFailed(error)) { DAQmxGetExtendedErrorInfo(errBuff, 2048); /*********************************************/ // DAQmx Stop Code /*********************************************/ DAQmxStopTask(taskHandle); DAQmxClearTask(taskHandle); printf("DAQmx Error: %s\n", errBuff); } return 0; } int32 CVICALLBACK DoneCallbackThermocouple(TaskHandle taskHandle, int32 status, void *callbackData) { int32 error = 0; char errBuff[2048] = { '\0' }; // Check to see if an error stopped the task. DAQmxErrChk(status); Error: if (DAQmxFailed(error)) { DAQmxGetExtendedErrorInfo(errBuff, 2048); DAQmxClearTask(taskHandle); printf("DAQmx Error: %s\n", errBuff); } return 0; }
Does anyone know why it is showing this behaviour, because I am clueless.
With kind regards,
Yami_Bas