Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

try to program NI-6008 using a free download C language compiler -LCC

I just got my NI-6008 unit and want to do some simple programming with C language.  The only C compiler I got is a free download version -- LCC, which can be got from:
 
The first thing I did is to use some sample C programs provided by NI, and try to compile them with LCC.  But I got several error message complaining
"undefined reference to _DAQmxBaseCreateTask" and other undefined functions.
 
I saw some previous posts in this forum mentioning that this issue needs to be solved case by case.  Can anyone help me to work out how to use LCC to program NI-6008?  LCC is a C language compiler, not a C++ compiler.
 
Thanks a lot.
 
 
0 Kudos
Message 1 of 9
(5,388 Views)

I haven’t had an experience with that specific compiler, but here is an excerpt from the DAQmx C Reference Manual that should help a bit:

 

Creating an ANSI C Application without LabWindows/CVI
NI-DAQmx has a C API that you can use to create applications. To create an application, follow these general steps:


Create a new project.
Open existing or new source files (.c), and add them to the project. Make sure you include the NI-DAQmx header file, nidaqmx.h, in your source code files. You can find this header file at NI-DAQ\DAQmx ANSI C Dev\include.
Add the NI-DAQmx import library, nidaqmx.lib, to the project. The import library files are located under NI-DAQ\DAQmx ANSI C Dev\lib\.
To view examples of NI-DAQmx applications, go to the NI-DAQ\Examples\DAQmx ANSI C Dev directory.
Build your application.

 

Also, if you are just looking for something to program your 6008 with, you can download a free evaluation copy of LabVIEW from this website. There are tons of LabVIEW examples that you can take advantage of as well.

 

 -GDE

0 Kudos
Message 2 of 9
(5,366 Views)

Thanks.

Actually I can only use NI-DAQmxBase, and I already copied the nidaqmxbase.lib and included the header file nidaqmxbase.h, but the problem is still there.  There might be some macro in the header that cannot be recognized by the LCC compiler, but I don't know how to solve it.

0 Kudos
Message 3 of 9
(5,356 Views)
Why do you have to use DAQmx base? You are using a win32 compiler and windows DAQmx has supported the 6008 for a while. The latest version is 8.1 and can be downloaded at [link removed].
0 Kudos
Message 4 of 9
(5,351 Views)

Thanks.  I tried to use DAQmx, the problem remains the same, i.e. error showing

undefined reference to _DAQmxCreateTask@8

undefined reference to *******

0 Kudos
Message 5 of 9
(5,335 Views)
The error you are seeing seems to indicate you aren't linking with an import library that exports the DAQ mx symbols.  The import library that NI ships is designed to work the MSVC and will not work with lcc.  If you have not already, you need to create an import library that works with lcc.  The lcc manual describes the process under "The Linker" -> "Importing a foreign library".
 
-Jeff
0 Kudos
Message 6 of 9
(5,329 Views)

Thanks, Jeff.

I tried the following:

"Importing a foreign library" within LCC, created a new "NIDAQmx.lib" based on the original one provided by NI (the original lib is 0.57M, the new one is 1.52M), and put it under the folder "c:\lcc\lib".  I also put the header "NIDAQmx.h" under the folder "c:\lcc\include".

Then I tried to MAKE the exe file.  Still, the same error happened.  LCC still complains the undefined reference to all the _DAQmx* functions.

Here is the source c file I used:

 


#include <stdio.h>
#include <NIDAQmx.h>

#define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else

int main(void)
{
 int         error=0;
 TaskHandle  taskHandle=0;
 uInt32      data;
 char        errBuff[2048]={'\0'};

 /*********************************************/
 // DAQmx Configure Code
 /*********************************************/
 DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
 DAQmxErrChk (DAQmxCreateCICountEdgesChan(taskHandle,"Dev1/ctr0","",DAQmx_Val_Rising,0,DAQmx_Val_CountUp));

 /*********************************************/
 // DAQmx Start Code
 /*********************************************/
 DAQmxErrChk (DAQmxStartTask(taskHandle));

 printf("Continuously polling. Press Ctrl+C to interrupt\n");
 while( 1 ) {
  /*********************************************/
  // DAQmx Read Code
  /*********************************************/
  DAQmxErrChk (DAQmxReadCounterScalarU32(taskHandle,10.0,&data,NULL));

  printf("\rCount: %d",data);
  fflush(stdout);
 }

Error:
 puts("");
 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;
}

0 Kudos
Message 7 of 9
(5,320 Views)

I just tried to build your example program with lcc, and it worked for me.  From the error you are seeing, it seems that either nidaqmx.lib is not in your project, or it is but you are still referencing the msvc one instead of the one you created.  I would guess that you are pointing to the msvc library.  You might try renaming that one (to something like nidaqmx.msvc), and try rebuilding.  Don't forget to change the name back when you are done.

Good Luck

Jeff

0 Kudos
Message 8 of 9
(5,314 Views)

Thanks a lot, Jeff.

 

It's working now.  I guess I need to add a link to the NIDAQmx.lib when I create the project in LCC.  After I did that, the linking got through smoothly.

 

Thanks again!

 

0 Kudos
Message 9 of 9
(5,306 Views)