07-30-2012 03:32 PM
Hi All,
My Objective is simple. I need a function that gives me the current temp that the sensor on NI USB TC 01 is reading. I have tried to look at the C Examples that come with the NI device, but that runs into some error altogether. I came across this function
int32 __CFUNC DAQmxGetCalDevTemp(const char deviceName[], float64 *data);
Here is my code snippet
const char deviceName[]="dev1";
float64 data;
int32 mytemp= DAQmxGetCalDevTemp( deviceName, &data);
I have an MFC app in which I am trying to get this temp value, if I use this function , I get 0 as the value of "data" and a -200197 as the value of mytemp. This is an error code, I get that, but I cansee the device in my MAX, so device is being recognised fine, its UI shows the right temperature, so changing ports on the PC wouldnt makea difference.
Has anybody used this function ? do You need some device configuration prior to using this function? Any help would be appreciated
Thanks
Vivek
07-30-2012 03:40 PM
If you are programming in MFC, why are you asking the question in a LabVIEW forum?
07-31-2012 12:59 PM
Hi Newbie,
Are you using any of the other DAQmx functions? Are you creating a task and setting timings? What error do you get when you try to run the shipping examples?
Thanks,
David B
07-31-2012 01:48 PM
Hi,
Just so I am clear and not confusing you, I am trying 2 different approaches here.
1) running their standard C example for Temp measurement (Cont Thermocouple Samples Int Clock)
2)writing a little code snippet of my own in my MFC application
The problem I am having with 1) is I get an error code -200077 (kindly see the attached pic)..
I think I narrowed the function call where its going wrong.But so far, I havent figured out how to substitute it with what the error message recommends.
DAQmxErrChk (error=DAQmxCfgSampClkTiming(taskHandle,"",10,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000));
I will paste the sample code as well..so that you can tell me what it is that can be corrected.
Now, for 2) , I am using other DAQmx function calls, albeit basic, like DAQmxCreateTask( ) ;DAQmxCreateAIThrmcplChan( PARAMETERS);
These 2 functions return a 0 which indicates they executed successfully, but when I run
int32 mytemp= DAQmxGetCalDevTemp( deviceName, &data); mytemp is -200197 (error code) & data is 0.0..
//////Code snippet
const char deviceName[]="dev1";float64 data;
uInt32 data1=0.0;
uInt32 arraySizeInElements;
TaskHandle taskHandle=0;
int32 data2=0;
int32 abc1;
abc1= DAQmxSelfTestDevice ( deviceName);
abc1=DAQmxCreateTask("task1",&taskHandle);
abc1=DAQmxCreateAIThrmcplChan(taskHandle,"Dev1"," ",0.0,100.0,DAQmx_Val_DegC,DAQmx_Val_J_Type_TC,DAQmx_Val_BuiltIn,25.0,"ai0");
abc1=DAQmxGetAITempUnits(taskHandle, "", &data2);
int32 mytemp= DAQmxGetCalDevTemp( deviceName, &data);
.The function of interest is DAQmxGetCalDevTemp() , I am not sure if I need to have some other functions setting the device up before I can use this function.
07-31-2012 01:50 PM
/*********************************************************************
*
* 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 (error=DAQmxCreateTask("task1",&taskHandle));
//DAQmxErrChk (DAQmxCreateAIThrmcplChan(taskHandle,"","",0.0,100.0,DAQmx_Val_DegC,DAQmx_Val_J_Type_TC,DAQmx_Val_BuiltIn,25.0,""));
DAQmxErrChk (error=DAQmxCreateAIThrmcplChan(taskHandle,"Dev1/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 (error=DAQmxCfgSampClkTiming(taskHandle,"",10,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000));
// DAQmxErrChk (error=DAQmxCfgImplicitTiming (taskHandle, DAQmx_Val_FiniteSamps, 1000));
DAQmxErrChk (error=DAQmxRegisterEveryNSamplesEvent(taskHandle,DAQmx_Val_Acquired_Into_Buffer,1000,0,EveryNCallback,NULL));
DAQmxErrChk (error=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-31-2012 02:45 PM
Again this is a LabVIEW forum.
I am not sure what you hoped to gain by posting massive amounts of C code here.
07-31-2012 02:58 PM
Ok..Should anyone be interested in replying, kindly goto this
http://forums.ni.com/t5/Measurement-Studio-for-VC/Temp-Measurement-in-USB-TC01/td-p/1990599
and reply.
Thanks
01-29-2016 01:05 PM
Try using function DAQmxReadAnalogScalarF64 to get temperature.
I got temperature data by Python
"dll.DAQmxReadAnalogScalarF64(taskHandle, timeout, byref(value), reserved)"