05-14-2012 11:06 AM
Hi All,
I have an MFC application that is full functional & I am trying to add some functionality for which I need to get the temperature from a NI USB TC01. I have added the NIDAQMx.h header & the associated library. All I want is a function from this library which gives me the temperature in Degree C,which I can use for some other things in my application. I am able to query the device for basic parameters like S/N & other things, however when I try to use the function DAQmxGetCalDevTemp(), all I get is a 0 in my Float64 data. What am I doing wrong, could some1 point me in the right direction? I am new at using this library, any guidance would be much appreciated.
<CODE SNIPPET>
float64 data;const char deviceName[]="dev1";
int32 mytemp= DAQmxGetCalDevTemp( deviceName, &data);
05-17-2012 02:48 PM
Hi Newbie_today,
It looks like the DAQmxGetCalDevTemp function returns the current temperature of the device in degrees Celsius and does not actually collect a sample of data. The help documentation for the C functions should be a good resource when trying to find out the behavior of a function. It is accessed by going to Start » All Programs » National Instruments » NI-DAQ » Text-Based Code Support » NI-DAQmx C Reference Help
In addition, there are example programs showing how to use DAQmx to communicate with devices available at the following location when the DAQmx drivers are installed with the C examples: Start » All Programs » National Instruments » NI-DAQ » Text-Based Code Support » ANSI C Examples
07-27-2012 03:24 PM
Ok...Its been a while, but since my issue didnt get resolved earlier, I had to switch to another project.Now I am back to getting this resolved. As Before, I have an MFC app in which I wana add a routine where in I can query the device(NI DAQ USB TC01) for its temperature periodically. Ideally, things would be great if I had a single function that I could use and which would return the temp (doesnt matter if it is in Degree Celcius or F)(the closest I came to was the function name I have mentioned in my earlier post),
So while that still remains the question to be answered(coz if I can successfully get this to work my company plans on ordering hundreds of these and including them in every vision system we ship out), today when I went into the ANSI C examples folder/Analog In/Temp Measurement/Cont Thermocouple Samples Int Clock, I loaded the C example in VS 2010 and when I try to run it, it gives me the following error(see attached pic)..
So Can someone tell me how to resolve this error?Much appreciated ..
Vivek
07-27-2012 03:29 PM
//This is the example C Code incase someone wants to see
/********************************************************************* * * ANSI C Example program: * ContThrmcplSamps-IntClk.c * * Example Category: * AI * * Description: * This example demonstrates how to make continuous, hardware-timed * temperature measurement using a thermocouple. * * Instructions for Running: * 1. Specify the Physical Channel where you have connected the * thermocouple. * 2. Enter the Minimum and Maximum temperature values in degrees C * you expect to measure. A smaller range will allow a more * accurate measurement. * 3. Enter the scan rate at which you want to run the acquisition. * 4. Specify the type of thermocouple you are using. * 5. Thermocouple measurements require cold-junction compensation * (CJC) to correctly scale them. Specify the source of your * cold-junction compensation. * 6. If your CJC source is "Internal", skip the rest of the steps. * 7. If your CJC source is "Constant Value", specify the value * (usually room temperature) in degrees C. * 8. If your CJC source is "Channel", specify the CJC Channel * name. * 9. Specify the appropriate Auto Zero Mode. See your device's * hardware manual to find out if your device supports this * attribute. * * Steps: * 1. Create a task. * 2. Create a Thermocouple (TC) temperature measurement channel. * 3. If your device supports Auto Zero Mode, set the AutoZero * attribute for all channels in the task. * 4. Call the Timing function to specify the hardware timing * parameters. Use device's internal clock, continuous mode * acquisition and the sample rate specified by the user. * 5. Call the Start function to program and start the acquisition. * 6. Read N samples and plot it. By default, the Read function * reads all available samples, but you can specify how many * samples to read at a time and the timeout value. Continue * reading data until the stop button is pressed or an error * occurs. * 7. Call the Clear Task function to clear the Task. * 8. Display an error if any. * * I/O Connections Overview: * Connect your thermocouple to the terminals corresponding to the * Physical Channel I/O Control value. * *********************************************************************/ #include <stdio.h> #include <NIDAQmx.h> #define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else int32 CVICALLBACK EveryNCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData); int32 CVICALLBACK DoneCallback(TaskHandle taskHandle, int32 status, void *callbackData); int main(void) { int32 error=0; TaskHandle taskHandle=0; char errBuff[2048]={'\0'}; /*********************************************/ // DAQmx Configure Code /*********************************************/ DAQmxErrChk (DAQmxCreateTask("",&taskHandle)); //DAQmxErrChk (DAQmxCreateAIThrmcplChan(taskHandle,"","",0.0,100.0,DAQmx_Val_DegC,DAQmx_Val_J_Type_TC,DAQmx_Val_BuiltIn,25.0,"")); DAQmxErrChk (DAQmxCreateAIThrmcplChan(taskHandle,"Dev1/ai0","ai0",0.0,100.0,DAQmx_Val_DegC,DAQmx_Val_J_Type_TC,DAQmx_Val_BuiltIn,25.0,"ai0")); //DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"",10.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000)); DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"",10.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000)); DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(taskHandle,DAQmx_Val_Acquired_Into_Buffer,1000,0,EveryNCallback,NULL)); DAQmxErrChk (DAQmxRegisterDoneEvent(taskHandle,0,DoneCallback,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 EveryNCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData) { int32 error=0; char errBuff[2048]={'\0'}; static int totalRead=0; int32 read=0; float64 data[1000]; /*********************************************/ // DAQmx Read Code /*********************************************/ DAQmxErrChk (DAQmxReadAnalogF64(taskHandle,-1,10.0,DAQmx_Val_GroupByScanNumber,data,1000,&read,NULL)); if( read>0 ) { 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 DoneCallback(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; }
07-27-2012 07:00 PM
Hi Newbie_today,
There is a KnowledgeBase article that goes through possible reason you are getting the Error -229771 message. The article is in reference to LabVIEW but both LabVIEW and C call into the same .dll so the information applies to both. Try the instructions in the following KnowlegeBase article and let me know how it works for you: Why Do I Receive Error -229771 at DAQmx Start Task.vi?
07-30-2012 11:19 AM
I did go throught the link, I noticed some of the NI services were not running, started that,and then ran the program, I ran into a different error code -200077. I was reading up on this, turns out, the code means 1 or more function calls/arguments in the sameple C code(that I have pasted above) that I am running is not supported by the NI USB TC 01. Now which one, I have no idea. SO if some one can see the sample C code and then tell me what function call/argument needs to be replaced, that would help greatly.
On a side note, if i wrote a small routine in which I am not calibrating the device in any way,
checkTemp()
{
const char deviceName[]="dev1";float64 data;
uInt32 data1;
uInt32 arraySizeInElements;
int32 abc1= DAQmxSelfTestDevice ( deviceName); //returns 0 -->Success
int32 xyz= DAQmxSelfCal ( deviceName); //returns -200445
int32 abc= DAQmxGetDevAccessorySerialNums(deviceName, &data1,arraySizeInElements ); //abc=0
int32 mytemp= DAQmxGetCalDevTemp( deviceName, &data); // "data" is given the value 0.00 .. "mytemp" has a -200197
}
07-31-2012 04:01 PM
Hi Newbie_today,
I do not believe the USB TC-01 will be able to perform the internal calibration. If you are trying to take a temperature measurement you can use the example code that you posted previously ContThrmcplSamps-IntClk.c. The main concern is that you would have to alter the example to remove timing aspects as the USB-TC01 does not have an internal sample clock.
08-01-2012 05:52 PM
Hi MIlan,
Yes what you are saying is right. I verified it with a function call that you cannot calibrate the TC and it doesnt have an interncal clock so the Clocking function call in the sample example has to be done away with.
In MAX(Measuremnt and AUtomation explorer, I was able to create a new aTask and can successfully get a temperature reading only when the Acquisition mode (under Timing) was set to 1 Sample (On Demand) (rest all settings left same as the example C code has it)...In all other instances(which rely on the timer) , it gave me errors..WHile this only verified that in the actual C Code,instead of DAQmxCfgSampClkTiming(), I need some other function that takes 1 reading independently of any timer. I have pretty much gone through the entire NIDAQMX.h header file but couldnt come up with any thing constructive for this(Would Software Triggering option be the right direction to pry in? ). Would you happen to know which function to use?
Thanks
VIvek
08-06-2012 11:06 AM
Just to give you a better idea, I am attaching a picture. I am looking for a function allowing the acquision mode to be 1 Sample (On Demand)
Thanks
08-08-2012 06:52 AM
Hi Newbie_today
You can actually use the DAQ Assistant in the screenshot that you posted from within CVI to help generate code! Try following the instructions in the Using the DAQ Assistant in LabWindows/CVI DevZone and see if it helps to generate the C function calls that you want to perform.