Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Error handling message is weird.

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,&bytesWritten);
        printf("Before write:  Bytes written: %d\n", bytesWritten);
        for (i=0; i < 5; i++)
        {
         //DAQmxErrChk (DAQmxWriteAnalogF64(taskHandle,DATA_LEN,1,10.0,DAQmx_Val_GroupByChannel,data,NULL,NULL));
   DAQmxWriteAnalogF64(taskHandle,DATA_LEN,1,10.0,DAQmx_Val_GroupByChannel,data,NULL,NULL);
                // How much does it think we wrote?
         //DAQmxErrChk (DAQmxGetWriteTotalSampPerChanGenerated(taskHandle,&bytesWritten));
   DAQmxGetWriteTotalSampPerChanGenerated(taskHandle,&bytesWritten);
                printf("Bytes written: %d\n", bytesWritten);
        }
        // Get rid of the current task and create and configure a new task.
 //DAQmxErrChk (DAQmxClearTask(taskHandle));
 DAQmxClearTask(taskHandle);
        // Try reseting device
        //DAQmxErrChk (DAQmxResetDevice(deviceName));
  DAQmxResetDevice(deviceName);
        // Create a new task and do it all again.
 //DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
 DAQmxCreateTask("",&taskHandle);
 //DAQmxErrChk (DAQmxCreateAOVoltageChan(taskHandle,channelName,"",-10.0,10.0,DAQmx_Val_Volts,""));
 DAQmxCreateAOVoltageChan(taskHandle,channelName,"",-10.0,10.0,DAQmx_Val_Volts,"");
    //DAQmxErrChk (DAQmxSetBufOutputBufSize(taskHandle, 512));
 DAQmxSetBufOutputBufSize(taskHandle, 512);
    DAQmxCfgSampClkTiming(taskHandle, "", 1000, DAQmx_Val_Rising, DAQmx_Val_ContSamps, 1000 );
 //DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle, "", 1000, DAQmx_Val_Rising, DAQmx_Val_ContSamps, 1000 ));
    //DAQmxErrChk (DAQmxTaskControl(taskHandle, DAQmx_Val_Task_Commit));
 DAQmxTaskControl(taskHandle, DAQmx_Val_Task_Commit);
        // With this new task see how many bytes it thinks were written. Should be 0.
        //DAQmxErrChk (DAQmxGetWriteTotalSampPerChanGenerated(taskHandle,&bytesWritten));
  DAQmxGetWriteTotalSampPerChanGenerated(taskHandle,&bytesWritten);
        printf("Second task - Before write:  Bytes written: %d\n", bytesWritten);
        //DAQmxErrChk (DAQmxWriteAnalogF64(taskHandle,DATA_LEN,1,10.0,DAQmx_Val_GroupByChannel,data,NULL,NULL));
  DAQmxWriteAnalogF64(taskHandle,DATA_LEN,1,10.0,DAQmx_Val_GroupByChannel,data,NULL,NULL);
        // Give it some time to do the write.
        Sleep(500);
        //DAQmxErrChk (DAQmxGetWriteTotalSampPerChanGenerated(taskHandle,&bytesWritten));
  DAQmxGetWriteTotalSampPerChanGenerated(taskHandle,&bytesWritten);
        printf("Second task - Bytes written: %d\n", bytesWritten);

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");
 c = getchar();
 c = getchar();
  return 0;
}
-----------------------------------------------------------------------------
 
This is an example of someone's code in this forum. This works for me. I just commented out every DAQmx functions except one to find if it causes a same problem.
 
So error routine is exactly same except printf() and AfxMessageBox().
DAQmxErrChk() is ONLY and EXACTLY used at the same time when creating a task.
 
But why are error results so different?
 
Thanks,
 
 
PS. Thanks for everytime whenever you answer.
 
 
 
 
 


Message Edited by anarkie on 07-23-2008 10:55 AM

Message Edited by anarkie on 07-23-2008 10:56 AM
I'm converting DAQ to DAQmx..from Parkoz.com
0 Kudos
Message 1 of 3
(2,886 Views)
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().
Rod T.
0 Kudos
Message 2 of 3
(2,859 Views)

Ah....I fixed the problem. The problem was at if() condition. I used a wrong code.

Thanks.

I'm converting DAQ to DAQmx..from Parkoz.com
0 Kudos
Message 3 of 3
(2,853 Views)