Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI
18 ratings:
 3.88 out of 5     Rate this Document

Programming NI-DAQ in Visual C++ .NET (MFC)

Primary Software: Measurement Studio>>Enterprise Edition (Full Development System)
Primary Software Version: 7.0
Primary Software Fixed Version: N/A
Secondary Software: Measurement Studio>>.NET Support, Measurement Studio>>Visual C++ Support
Hardware: Multifunction DAQ (MIO)

Problem:
What options do I have when programming NI-DAQ using Visual C++ .NET (MFC)?

Solution:
Refer to this table when using Visual C++.NET and the NI-DAQ Driver (Traditional or DAQmx ) to determine if you can create a NI-DAQ application whether you have Measurement Studio installed or not. You can follow the links on the table itself or use the links at the bottom of the page for more information about the options.
  • Measurement Studio for the Visual Studio 2003/2005/2008 environments provides a collection of managed .NET and MFC C++ libraries* for advanced analysis, scientific user interface controls and measurement data networking. It also provides code generation and integration tools with Visual Studio. Refer to the Measurement Studio for Visual Studio 2003/2005/2008 column if you are developing a NI-DAQ application using Visual Studio 2003/2005/2008 and you have Measurement Studio 7.0 or later.

  • Measurement Studio Support for Visual Studio 6.0 provides ActiveX controls, MFC Visual C++ libraries, and integration tools for use with Visual C++ 6.0 and Visual Basic 6.0. This support is available as a part of Measurement Studio 7.0 (Professional Edition or higher). Refer to this column if you are developing a DAQ application using Visual Basic 6.0 or Visual C++ 6.0 and you have Measurement Studio Support for Visual Studio 6.0 installed. This was previously available as Measurement Studio 6.0.

  • Visual Studio only (without Measurement Studio) refers to the development options if you have only Visual Studio and no Measurement Studio packages. This means you use Visual Studio 2003 or higher for developing applications using Visual C++.NET (MFC).
  Measurement Studio for Visual Studio 2003/2005/2008 Measurement Studio Support for Visual Studio 6.0 Visual Studio only
(without Measurement Studio)
Visual C++ .NET (MFC) Traditional NI-DAQ Yes* N/A Yes
NI-DAQmx Optimal * N/A Yes
OPTIMAL: Project wizards, code generation, and configuration tools are provided to accelerate DAQ application development.
YES: Native components are provided for this purpose and shipping examples are included.
N/A: The particular Measurement Studio package does not provide support for the particular language. Refer to the link for more information.

* MFC C++ libraries available for Visual Studio 2005 and 2003 only.


Visual C++ .NET with Measurement Studio Support for Visual Studio 2003/2005/2008
  1. Traditional NI-DAQ
    • National Instruments does not provide native .NET or Visual C++ (MFC) libraries for Traditional NI-DAQ. Measurement Studio Support for Visual Studio 2003/2005/2008 will not provide you any additional functionality for developing Traditional NI-DAQ applications in Visual Studio 2003/2005/2008.
    • Use the ANSI C API that is available by installing the Traditional NI-DAQ driver. This does not require Measurement Studio. Refer to the Visual C++ .NET without Measurement Studio section for more information.
    • You can download examples by searching for visual daq on the NI Technical Support Web page.
    • You can use the Traditional NI-DAQ ActiveX controls to perform data acquisition. The ActiveX controls are provided with the Traditional NI-DAQ Driver and do not require Measurement Studio. The CWDAQ control is installed as a part of the Traditional NI-DAQ Driver. Wrappers for using these ActiveX controls from Visual C++ .NET are available in Knowledgebase Article 2IECTCLXL linked below.
  2. NI-DAQmx
    • Measurement Studio support for Visual Studio 2003/2005/2008 provides Visual C++ class libraries, help integration, and code generation tools for NI-DAQmx. You will need to run the NI-DAQmx driver installation after installing Measurement Studio to get the NI-DAQmx class libraries.
    • You can find examples in the following default directory location: \National Instruments\MeasurementStudio70\VCNET\Examples\DAQmx or \National Instruments\MeasurementStudioVS2003\VCNET\Examples\DAQmx. Double-click the .vcproj file to open the project.

Visual C++ .NET with Measurement Studio Support for Visual Studio 6.0

Note: You must have Visual Studio 6.0 to install this support.
  1. Traditional NI-DAQ
    • National Instruments does not provide native .NET or Visual C++ (MFC) libraries for Traditional NI-DAQ. Measurement Studio Support for Visual Studio 6.0 will not provide you any additional functionality for developing Traditional NI-DAQ applications in Visual Studio 2003/2005/2008.
    • Use the ANSI C API that is available by installing the Traditional NI-DAQ driver. This does not require Measurement Studio. Refer to the Visual C++ .NET without Measurement Studio section below for more information.
    • You can download examples by searching for visual daq on the NI Technical Support Web page
    • Almost all of these examples will be in Visual C++ 6.0, but Visual Studio 2008/2005/.NET 2003 will automatically update the project to a Visual Studio .NET solution for you.
    • You can use the Traditional NI-DAQ ActiveX controls to perform data acquisition. The CWDAQ ActiveX control are provided with the Traditional NI-DAQ Driver and does not require Measurement Studio. The CWDAQ control is installed as a part of the Traditional NI-DAQ Driver. Wrappers for using these ActiveX controls from Visual C++ .NET are available in Knowledgebase Article 2IECTLXL linked below.
  2. NI-DAQmx
    • National Instruments provides a C API for NI-DAQmx. This is available as a part of the driver and does not require Measurement Studio.
    • Measurement Studio Support for Visual Studio 6.0 will not provide you any additional functionality for developing NI-DAQmx applications in Visual Studio 2003.
    • You can find examples in the following default directory location: \National Instruments\NI-DAQ\Examples\DAQmx ANSI C. These are examples written using Visual Studio 6.0, but Visual Studio 2003/2005/2008 will automatically update the project to a Visual Studio .NET solution for you. Refer to Visual C++ .NET without Measurement Studio for information on how to manually add the NI-DAQmx headers and libraries to the Visual Studio 2008/2005/.NET 2003 environment.
    • Refer to examples in the Visual C++ .NET without Measurement Studio section for information on how to add NI-DAQmx functions to the examples.

Visual C++ .NET without Measurement Studio
  1. Traditional NI-DAQ
    • National Instruments does not provide native .NET components or Visual C++ (MFC) class libraries for Traditional NI-DAQ.
    • For this scenario, you can run the examples that are installed with NI-DAQ, that were initially written to be run with Visual C++ 6.0. The examples are found in the following default directory location: \National Instruments\NI-DAQ\Examples\VisualC. You can run these examples in Visual C++.NET by completing the following steps:
      1. Open Visual Studio.NET.
      2. Select File»New»Project.
      3. In the project window, select Visual C++ Projects and Win32Project.
      4. Enter a project name. Click OK.
      5. Select Application Settings.
      6. On the Application Settings, select Console Application and Empty Project. Click Finish. This will create the empty project for you.
      7. In the Solution Explorer box, right-click on the source files, and select Add »Add Existing Item.
      8. Navigate to the example path: \National Instruments\NI-DAQ\Examples\VisualC, and then into the specific example you want to run.
      9. Select the specific .c file you want to run, and click Open.
      10. Add the library files that are needed to run these applications. You can find these libraries at the following location: \National Instruments\NI-DAQ\Lib. Add these to your project by right-clicking on the source files, and selecting Add»Add Existing Item.
      11. Navigate to the above path. Once you are in the correct folder, you will want to change the files types that you are looking for from C++ file type to All files, then select both library files (nidaq32.lib and nidex32.lib), and click Open. This will add both files to your project and the file should now compile and run.
      12. Run the program by clicking the blue arrow on the toolbar. (If you still have errors, check to make sure the Include and Library paths are correct.
        Note:Check the paths by selecting Tools»Options. Then select Projects»Visual C++ Directories. Select Include files, and make sure that there is a path added to any .h files that your project references. Specifically, be sure that the following path is there: \National Instruments\NI-DAQ\Include. Make sure that under Library Files, there is the following path to the library files: \National Instruments\NI-DAQ\Lib.
    • You can also add the Traditional NI-DAQ ActiveX controls to perform data acquisition. The ActiveX controls are provided with the Traditional NI-DAQ Driver and do not require Measurement Studio. The CWDAQ control is installed as a part of the Traditional DAQ Driver. Wrappers for using these ActiveX controls from Visual Studio .NET are available in Knowledgebase Article 2IECTLXL linked below.

  2. NI-DAQmx
    • National Instruments provides a C API for NI-DAQmx. This is available as a part of the driver and does not require Measurement Studio.
    • You can find examples in the following default directory location: \National Instruments\NI-DAQ\Examples\DAQmx ANSI C. These examples are written using Visual C++ 6.0. Visual Studio 2003/2005/2008 will automatically convert the Visual C 6.0 projects to the correct format. To manually add the NI-DAQmx libraries to your projects, select Tools»Options. In the Options dialog box, select Projects»Directories. Select include and library files. For example, you will want to add the following path for include files: \National Instruments\NI-DAQ\DAQmx ANSI C Dev\include, and a path for the following library file: \National Instruments\NI-DAQ\DAQmx ANSI C Dev\lib\msvc.


Related Links:
Developer's Zone: Text Based NI-DAQmx Examples
KnowledgeBase 2IECTLXL: Why Are the Microsoft Visual C++ .NET-Generated Wrappers for Measurement Studio ActiveX Controls Incomplete?
KnowledgeBase 317742FQ: Programming NI-DAQ in Text-Based Languages
KnowledgeBase 3146J6FQ: Programming NI-DAQ in Visual Basic 6.0
KnowledgeBase 3178NEFQ: Programming NI-DAQ in Visual Basic .NET
KnowledgeBase 317BPGW3: Programming NI-DAQ in Visual C++ 6.0
KnowledgeBase 3186P9W3: Programming NI-DAQ in Visual C# .NET

Attachments:





Report Date: 09/08/2003
Last Updated: 01/19/2009
Document ID: 317CP7W3

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit