Discussion:
Error handling message is weird.
(too old to reply)
anarkie
2008-07-23 16:10:10 UTC
Permalink
Hello?
 
I'm testing if DAQmx works with an old PCI-6025E. I wrote a console program and an MFC program.
 
The error handler, DAQmxErrChk() works fine with the console but doesn't work with the MFC. I'm using VC++ 6.
 
An MFC code is
 
--------------------------------------------------
 
#define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else goto Error
 
int CTestDialogClass::FindMyDAQLegacyDevice_With_DAQmx(){   int  error=0; char errBuff[2048]={'\0'}; char devNames[256]={'\0'};  char testDevName[256]={'\0'};   TaskHandle taskHandle=0;      DAQmxGetDevProductType("Dev1", testDevName, 256); DAQmxGetSysDevNames(devNames,256);
 m_cstringProductName = testDevName; m_cstringDeviceName = devNames;
 DAQmxErrChk(DAQmxCreateTask("",&taskHandle)); //DAQmxErrChk(DAQmxStartTask(taskHandle));
Error: if( DAQmxFailed(error) )  DAQmxGetExtendedErrorInfo(errBuff,2048);   if( taskHandle!=0 ) {  /*********************************************/  // DAQmx Stop Code  /*********************************************/  DAQmxStopTask(taskHandle);  DAQmxClearTask(taskHandle); } if( DAQmxFailed(error) )  AfxMessageBox("Error!", MB_OK, 0); //it results this automatically.  return 0;
}
----------------------------------------------------------------------
DAQmxErrChk() is used a lot in a console program, it works like a charm. When I run this MFC, it automatically shows Erorr! message box.
 
A console code is...
------------------------------------
#include <stdio.h>#include <Windows.h>#include <NIDAQmx.h>
#define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else#define DATA_LEN 500
 
int main(void){
 
 int         error=0; TaskHandle taskHandle=0; char  errBuff[2048]={'\0'}; float64         data[DATA_LEN]; uInt64          bytesWritten = 0;int i;
 
// Build the channel name.char            channelName[100];char            deviceName[100];char            deviceNumber[10];char            c; /*********************************************/ // DAQmx Configure Code /*********************************************/ DAQmxErrChk (DAQmxCreateTask("",&taskHandle));  //DAQmxErrChk (DAQmxCreateAOVoltageChan(taskHandle,channelName,"",-10.0,10.0,DAQmx_Val_Volts,"")); DAQmxCreateAOVoltageChan(taskHandle,channelName,"",-10.0,10.0,DAQmx_Val_Volts,""); DAQmxSetBufOutputBufSize(taskHandle, 512);    //DAQmxErrChk (DAQmxSetBufOutputBufSize(taskHandle, 512));    //DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle, "", 1000, DAQmx_Val_Rising, DAQmx_Val_ContSamps, 1000 )); DAQmxCfgSampClkTiming(taskHandle, "", 1000, DAQmx_Val_Rising, DAQmx_Val_ContSamps, 1000 );
 /*********************************************/ // DAQmx Write Code /*********************************************/        //DAQmxErrChk (DAQmxTaskControl(taskHandle, DAQmx_Val_Task_Commit));  DAQmxTaskControl(taskHandle, DAQmx_Val_Task_Commit);        //DAQmxErrChk (DAQmxGetWriteTotalSampPerChanGenerated(taskHandle,&bytesWritten));  DAQmxGetWriteTotalSampPerChanGenerated(taskHandle,&bytesWrit
RT4CY
2008-07-24 22:40:08 UTC
Permalink
Could you try running the MFC app without the DAQmxErrChk() macro and see if you get errors?  This will help us determine whether it's a problem with DAQmxErrChk().
anarkie
2008-07-25 13:10:10 UTC
Permalink
Ah....I fixed the problem. The problem was at if() condition. I used a wrong code.
Thanks.

Loading...