Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Programming NI-DAQmx in Visual C++ .NET 2003

Hi,
 
I have problems in using NI-DAQmx in VC+.NET 2003. I have read the KB article https://www.ni.com/en/support/documentation/supplemental/18/archived--programming-traditional-ni-daq... and I followed the steps in the last part for NI-DAQmx. However, when I compiled my project, this error still came:
 
error LNK2019: unresolved external symbol _DAQmxCreateTask@8 referenced in function "public: long __thiscall CDAQmxfunc::Configure_AcqIntClkAnlgStart(char const * const,double,double,unsigned long,double,unsigned long *,unsigned long *)" (?Configure_AcqIntClkAnlgStart@CDAQmxfunc@@QAEJQBDNNKNPAK1@Z)
 
which means the lib files still couldn't be found. After I added the NIDAQmx.lib in my project, this problem is solved.  Did I make the right move? Also, when I referred to the DAQmx ANSI C samples for NI-DAQmx, I saw only this header file NIDAQmx.h is included. Is it the same in VC++.NET?
 
Thank you very much.
 
David
0 Kudos
Message 1 of 4
(4,221 Views)

Hi David,

You did the correct thing by adding the NIDAQmx.lib file to your project. Also, the NIDAQmx.h file is the same.

Regards,
Hal L.

0 Kudos
Message 2 of 4
(4,206 Views)

I have a similar problem in VS 2008.  I can compile the example code (VC_ContFreq_IntClk_SCXI1126) no problem from Visual Studio 2008.

 

However, when I create my own project in visual studio with the same #includes i get the same errors:  

 

Compiling...

DTRTestNov2010.c

Linking...

DTRTestNov2010.obj: error LNK2019: unresoloved external symbol _DAQmxClearTask@4 reference in function _main

DTRTestNov2010.obj: error LNK2019: unresoloved external symbol _DAQmxStopTask@4 reference in function _main

and so on... for all other function calls I made.  

 

i am not a pro at c-programming.  Am I supposed to setup a 'linker' somehow? 

 

Thanks!

Sean

 

Here is my c-code (which operates in matlab typically, but I think is spawning a memory leak, so i'd like to test it in native C)

 

 

#include <stdio.h>
#include <NIDAQmx.h>
#define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else
int main(void)
{
int32       error=0;
TaskHandle  masterTaskHandle=0;
TaskHandle  slaveTaskHandle=0;
int32       read;
int32 fs=30000;
int32 samplesPerLoop=30000;
int32 channels=4;
int32 arrayLength;
float64     data[30000];
char        errBuff[2048]={'\0'};
arrayLength  = samplesPerLoop * channels;
/*********************************************/
// DAQmx Configure Code
/*********************************************/
DAQmxErrChk (DAQmxCreateTask("",&masterTaskHandle));
DAQmxErrChk (DAQmxCreateTask("",&slaveTaskHandle));
DAQmxErrChk (DAQmxCreateAIVoltageChan(masterTaskHandle,"Dev1/ai0:3","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxCreateAIVoltageChan(slaveTaskHandle,"Dev1/ai0:3","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxCfgSampClkTiming(masterTaskHandle,"",fs,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,samplesPerLoop));
DAQmxErrChk (DAQmxCfgSampClkTiming(slaveTaskHandle,"",fs,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,samplesPerLoop));
DAQmxErrChk (DAQmxCfgInputBuffer(masterTaskHandle,samplesPerLoop*2));
DAQmxErrChk (DAQmxCfgInputBuffer(slaveTaskHandle,samplesPerLoop*2));
DAQmxErrChk (DAQmxExportSignal(masterTaskHandle,DAQmx_Val_StartTrigger,"RTSI0"));
DAQmxErrChk (DAQmxCfgDigEdgeStartTrig(slaveTaskHandle,"RTSI0",DAQmx_Val_Rising));
DAQmxErrChk (DAQmxSetExportedSampClkTimebaseOutputTerm(masterTaskHandle,"/Dev1/RTSI8"));
DAQmxErrChk (DAQmxSetSampClkTimebaseSrc(slaveTaskHandle,"RTSI8"));
DAQmxErrChk (DAQmxSetExportedSyncPulseEventOutputTerm(masterTaskHandle,"/Dev1/RTSI9"));
DAQmxErrChk (DAQmxSetSyncPulseSrc(slaveTaskHandle,"RTSI9"));
/*********************************************/
// DAQmx Start Code
/*********************************************/
DAQmxErrChk (DAQmxStartTask(slaveTaskHandle));
DAQmxErrChk (DAQmxStartTask(masterTaskHandle));
/*********************************************/
// DAQmx Read Code
/*********************************************/
DAQmxErrChk (DAQmxReadAnalogF64(masterTaskHandle,samplesPerLoop,5.0,DAQmx_Val_GroupByChannel,data,samplesPerLoop,&read,NULL));
DAQmxErrChk (DAQmxReadAnalogF64(slaveTaskHandle,samplesPerLoop,5.0,DAQmx_Val_GroupByChannel,data,samplesPerLoop,&read,NULL));
printf("Acquired %d points\n",read);
Error:
if( DAQmxFailed(error) )
DAQmxGetExtendedErrorInfo(errBuff,2048);
if( masterTaskHandle!=0 )  {
/*********************************************/
// DAQmx Stop Code
/*********************************************/
DAQmxStopTask(slaveTaskHandle);
DAQmxStopTask(masterTaskHandle);
DAQmxClearTask(slaveTaskHandle);
DAQmxClearTask(masterTaskHandle);
}
if( DAQmxFailed(error) )
printf("DAQmx Error: %s\n",errBuff);
printf("End of program, press Enter key to quit\n");
getchar();
return 0;
}

 

0 Kudos
Message 3 of 4
(3,817 Views)

Hi Sean,

 

Yes, you must tell the linker where nidaqmx.lib is located. Here are a couple of KBs explaining how to do this:

 

When Compiling a DAQmx ANSI C Example in Visual C++ I Receive Link Errors

Location of ANSI C NI-DAQmx Shipping Examples and DAQmx Library File for Windows

 

Brad

---
Brad Keryan
NI R&D
0 Kudos
Message 4 of 4
(3,805 Views)