Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

continuous data acquisition, visual c, excel

 

Hi,


I’m trying to build an MFC application with MSVC++6, where I would continuously acquire
samples from 2 channels of a USB-6289. I’m using the DAQmx C functions. First I declear the callback fun as static function in the dialog class
:


       class DataCollectionWin : public CDialog 
{.....

static int32 CVICALLBACK EveryNCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData);
static int32 CVICALLBACK DoneCallback(TaskHandle taskHandle, int32 status, void *callbackData);

CString str;
 char* FileName;

 

Click "start tracking" to start data collection and save to an excel file:

 

void DataCollectionWin::OnStartTracking()
{
    // TODO: Add your control notification handler code here

     
float64 data[2000];
int32    read=0;
int32 errorcode=0;
int i,length;
int32   error=0;
    char    errBuff[2048]={'\0'};
    

//********Connect DAQ channels***********


    
    CString    szButtonText;
    CString szFilter = "Excel Files (*.xls)|*.xls|All Files (*.*)|*.*||";
    CFileDialog dlg(FALSE,"Excel",NULL,OFN_OVERWRITEPROMPT,szFilter);

    GetDlgItem( IDStartTracking)->GetWindowText( szButtonText );

    /* if the text read Start, then we start, else we stop tracking */
    if (  szButtonText == "Start Tracking" )
    {
       
          if(dlg.DoModal()==IDOK)
    {
        str=dlg.GetPathName ();
        UpdateData(TRUE);

        if(!cfData.Open (str,CFile::modeCreate|CFile::modeReadWrite))
        {
        
            MessageBox("create/read/write file fail","warning", MB_ICONWARNING | MB_OK);

        }
    
        length=str.GetLength();
        FileName=new char[length];
        for(i=0;i<length;i++)
        *(FileName+i)=str.GetAt(i);
        *(FileName+length)=NULL;


   DAQmxErrChk(DAQmxCreateTask ("connect", &taskHandle)); DAQmxErrChk(DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai0,Dev1/ai1","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));
        DAQmxErrChk(DAQmxReadAnalogF64(taskHandle,1000,-1,DAQmx_Val_GroupByChannel,data,2000,&read,NULL));
        DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(taskHandle,DAQmx_Val_Acquired_Into_Buffer,1000,0,EveryNCallback,NULL));
        DAQmxErrChk (DAQmxRegisterDoneEvent(taskHandle,0,DoneCallback,NULL));

        Error:
    if( DAQmxFailed(error) ) {
        DAQmxGetExtendedErrorInfo(errBuff,2048);
        MessageBox(errBuff);
        DAQmxStopTask(taskHandle);
        DAQmxClearTask(taskHandle);
            return;
    }

        GetDlgItem( IDStartTracking )->SetWindowText("Stop Tracking");
    
    }

    }
    else
    //    nStopTracking();
    {    GetDlgItem( IDStartTracking )->SetWindowText("Start Tracking");
    DAQmxStopTask(taskHandle);
    DAQmxClearTask(taskHandle);
     cfData.Close();

    }
    
    }



static int32 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];
    FILE *datafile;
    datafile = fopen(FileName,"w+");
    int i;
 

 if (datafile == NULL )
      printf( "The file was not opened\n" );

    /*********************************************/
    // DAQmx Read Code
    /*********************************************/
    DAQmxErrChk(DAQmxReadAnalogF64(taskHandle,1000,-1,DAQmx_Val_GroupByChannel,data,2000,&read,NULL));
    printf("data number: %d\n",read);
        if( read>0 ) {
         
    for (i=0;i<2000;i++)
    {
            fprintf(datafile,"%f\n",data[i]);
        }

        fflush(stdout);
     }
  
       
             Error:
    if( DAQmxFailed(error) )
    {
        DAQmxGetExtendedErrorInfo(errBuff,2048);
        DAQmxStopTask(taskHandle);
        DAQmxClearTask(taskHandle);
        printf("DAQmx Error: %s\n",errBuff);
            return 0;
    }

}

static int32 CVICALLBACK DoneCallback(TaskHandle taskHandle, int32 status, void *callbackData)
{
    int32   error=0;
    char    errBuff[2048]={'\0'};

 

    printf("hello"); 

 

    // Check to see if an error stopped the task.
    DAQmxErrChk (status);

Error:
    if( DAQmxFailed(error) ) {        DAQmxGetExtendedErrorInfo(errBuff,2048);
              DAQmxClearTask(taskHandle);
            }
    return 0;
}

 


 Can anyone check the codes for me? when i run the program, no data is save into the excel file. It seems the EveryNCallback function does not work, because when I put "printf("hello"); "for checking,nothing happens. Also there is an debug assertion error (see enclosure). 

 

Actually how does the callback function work to continuously collect the data? 


 

Thank you!

kg 

0 Kudos
Message 1 of 16
(10,275 Views)
Can anyone help me on it, please?
0 Kudos
Message 2 of 16
(10,252 Views)

Hello,

 

So is your read code not working at all? Are you getting data and just not able to write it to excel?

 

Have you tried the ANSI C examples? Which version of Measurement Studio are you using?

With warm regards,

David D.
0 Kudos
Message 3 of 16
(10,240 Views)

Hi, David,

 

Thank you very much for your reply. When I run the ANSI C sample, it seems ok. I tried to use DAQmxReadAnalogF64 to collect 2000 samples and save to a CFile. No problem. But when I add the everyNCallback to continuously collect data, then it seems not work. Do I need to add head file for measurement studio? I only add "NIDAQmx.h". Must I use measurement studio to complete this task? I thought I can directly use NIDAQmx library for this purpose. Please advice. Thanks!

0 Kudos
Message 4 of 16
(10,234 Views)

Hello,

 

You can use the DAQmx functions, yes. I was just curious how Measurement Studio played into this equation since you posted in the Measurement Studio forum rather than the Multifunction DAQ forum. Have you tried the "Cont Acq - Int Clk" example? This should give you a template for acquiring data continuously using ANSI C.

With warm regards,

David D.
0 Kudos
Message 5 of 16
(10,226 Views)
I was directed to this forum. I pasted similar questions in Multifunction DAQ forum. But was told I should come here for help. I tried the example you mentioned. Seems no problem. Anyone can help checking the codes please?
0 Kudos
Message 6 of 16
(10,221 Views)

Hello,

 

It looks the original post was in the LabVIEW forum. For future reference, the best place for questions about the DAQmx functions or programming in DAQmx (even text-based) is the Multifunction DAQ forum, this forum is for questions about Measurement Studio functions or programming.

 

All that aside, have you tried the standard debugging methods? IE diff-ing your program with the example, single-stepping to see exactly where you are getting the error? Have you tried using any other callbacks successfully? Did you check the C++ documentation for asserts as mentioned in that error?

With warm regards,

David D.
0 Kudos
Message 7 of 16
(10,210 Views)

I tried to debug. It didn't get into the everyNcallback function. I get following error information. It seems that I miss sth. Can anyone give me a clue?

 

Loaded 'ntdll.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\kernel32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\nicaiu.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\nipalu.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\nipalut.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\msvcr71.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\nipal32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\advapi32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\rpcrt4.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\secur32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\setupapi.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\msvcrt.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\gdi32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\user32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\shell32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\shlwapi.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\niorbu.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\nirpc.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\wsock32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\ws2_32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\ws2help.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\nimdbgu.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\nimstsu.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\nimxdfu.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\nidmxfu.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\nimru2u.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\nidimu.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\nimxpu.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\nimhwcfu.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\ole32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\oleaut32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\nimercu.dll', no matching symbolic information found.

0 Kudos
Message 8 of 16
(10,204 Views)
Loaded symbols for 'C:\WINDOWS\system32\MFC42D.DLL'
Loaded symbols for 'C:\WINDOWS\system32\MSVCRTD.DLL'
Loaded symbols for 'C:\WINDOWS\system32\MFCO42D.DLL'
Loaded 'C:\WINDOWS\system32\shimeng.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\imm32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\lpk.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\usp10.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.2982_x-ww_ac3f9c03\comctl32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\comctl32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\uxtheme.dll', no matching symbolic information found.
Loaded 'C:\Program Files\Aculearn\AcuSTUDIO5\MsnHookDll.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\winmm.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\serwvdrv.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\umdmxfrm.dll', no matching symbolic information found.
Loaded 'C:\Program Files\SweetIM\Messenger\mgAdaptersProxy.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\MSCTF.dll', no matching symbolic information found.
Loaded 'C:\kaiguo\Powerword 2003\Cjktl32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\Downloaded Program Files\BDPlugin.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\version.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\apphelp.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\MSCTFIME.IME', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\comdlg32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\clbcatq.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\comres.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\cscui.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\cscdll.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\browseui.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\userenv.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\ntshrui.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\atl.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\netapi32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\shdocvw.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\crypt32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\msasn1.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\cryptui.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\wintrust.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\imagehlp.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\wininet.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\wldap32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\riched20.dll', no matching symbolic information found.
Loaded 'C:\Program Files\National Instruments\MAX\mxs.dll', no matching symbolic information found.
Loaded 'C:\Program Files\National Instruments\MAX\mxsutils.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\msvcp71.dll', no matching symbolic information found.
Loaded 'C:\Program Files\National Instruments\MAX\mxsout.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\mswsock.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\hnetcfg.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\wshtcpip.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\nismslu.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\nidevldu.dll', no matching symbolic information found.
Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\NI6535.sdc', no matching symbolic information found.
Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\nics.sdc', no matching symbolic information found.
Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\NIDSA.sdc', no matching symbolic information found.
Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\niem.sdc', no matching symbolic information found.
Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\nies.sdc', no matching symbolic information found.
Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\NIFILTER.sdc', no matching symbolic information found.
Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\NIHWDB.sdc', no matching symbolic information found.
Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\NIMAS.sdc', no matching symbolic information found.
Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\NISCXI.sdc', no matching symbolic information found.
Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\nisd.sdc', no matching symbolic information found.
Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\NISFT.sdc', no matching symbolic information found.
Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\niss.sdc', no matching symbolic information found.
Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\NISWCH.sdc', no matching symbolic information found.
Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\nitio.sdc', no matching symbolic information found.
Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\niwf.sdc', no matching symbolic information found.
Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\nixs.sdc', no matching symbolic information found.
Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\Compat\NI5690.sdc', no matching symbolic information found.
Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\Compat\NIDWG.sdc', no matching symbolic information found.
Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\Compat\NIHSD.sdc', no matching symbolic information found.
Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\Compat\NIPS.sdc', no matching symbolic information found.
Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\Compat\NIRFSA.sdc', no matching symbolic information found.
Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\Compat\NISL.sdc', no matching symbolic information found.
Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\Compat\NISRC.sdc', no matching symbolic information found.
Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\Compat\NISYNC.sdc', no matching symbolic information found.
Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\Compat\NITNR.sdc', no matching symbolic information found.
Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\Compat\NITSU.sdc', no matching symbolic information found.
0 Kudos
Message 9 of 16
(10,203 Views)
Loaded 'C:\WINDOWS\system32\nixsxu.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\nisciu.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\nicdru.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\nimsdru.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\nimsdxu.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\nicdxu.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\nitioru.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\nixsru.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\nicalgu.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\nisnseu.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\nilesru.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\browseui.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\shdocvw.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\crypt32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\msasn1.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\cryptui.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\wintrust.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\imagehlp.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\wininet.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\wldap32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\riched20.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\browseui.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\shdocvw.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\crypt32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\msasn1.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\cryptui.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\wintrust.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\imagehlp.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\wininet.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\wldap32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\riched20.dll', no matching symbolic information found.
The thread 0x1320 has exited with code 0 (0x0).
The thread 0xD20 has exited with code 0 (0x0).
The thread 0x11F0 has exited with code 0 (0x0).
The thread 0xD50 has exited with code 0 (0x0).
The thread 0xFF8 has exited with code 0 (0x0).
SCIFIS Project.exe DLL DETACH!!!!!
The thread 0x1058 has exited with code 0 (0x0).
Detected memory leaks!
Dumping objects ->
C:\Documents and Settings\Lei Fu\Desktop\SCIFIS Project\DataCollectionWin.cpp(221) : {186} normal block at 0x00DA73F0, 63 bytes long.
 Data: <C:\Documents and> 43 3A 5C 44 6F 63 75 6D 65 6E 74 73 20 61 6E 64
C:\Documents and Settings\Lei Fu\Desktop\SCIFIS Project\DataCollectionWin.cpp(221) : {157} normal block at 0x00DA6F20, 63 bytes long.
 Data: <C:\Documents and> 43 3A 5C 44 6F 63 75 6D 65 6E 74 73 20 61 6E 64
Object dump complete.
The thread 0x11AC has exited with code 0 (0x0).
The program 'C:\Documents and Settings\Lei Fu\Desktop\SCIFIS Project\Debug\SCIFIS Project.exe' has exited with code 0 (0x0).
0 Kudos
Message 10 of 16
(10,202 Views)