Generating Code in Measurement Studio
This section describes what happens during code generation in Measurement Studio and how to generate code using the DAQ Assistant.
Types of Code Generation
You can generate two types of code in Measurement Studio. For general information about the types of code and special considerations, refer to Generating Code.
- Example—This option creates a function that has the task and adds the source files to the project.
- Configuration—The DAQmxLoadTask function is replaced with a call to a DAQ Assistant-generated function that builds the task programmatically.
Caution Although generated configuration code includes code to create global virtual channels and tasks, it does not include code to create scales. If you generate configuration code for deployment of applications that include scales, you must ensure that the scales are configured in the target computer. Refer to Deployment in the NI-DAQmx Help for deployment options.
Generating Code in Measurement Studio
After you configure and save a task, a class is generated and added to the project. The class contains the source code that corresponds to the configuration information that is stored in the .mxb file.
Note When you use the DAQ Assistant configuration editor to make changes to the DAQmx task class, the .mxb file is saved and the task code is regenerated. If you make changes directly to the generated source code file, those changes are lost when the source code for the .mxb file is regenerated. To enhance or extend the code that the DAQ Assistant generates, you can copy the source code file, change the name of the DAQmx task class, and add the copied file to the project. The copied file is not associated with a .mxb file. As a result, the DAQ Assistant does not overwrite the source code file. |
Generating Code for a .NET DAQmx Task Class
The DAQmx task class code is contained in a hidden .cs or .vb source code file in the project. This source code file has the same base name as the .mxb file, but has an extension that corresponds to the language of the source code. Complete the following steps to view the hidden .cs or .vb file:
- Select Show All Files in the Solution Explorer toolbar.
- In the Solution Explorer, expand the .mxb file node.
- Right-click the .cs or .vb file and select View Code to view the code.
To generate the source code, the .mxb file has a CustomTool property that associates the DAQ Assistant with the .mxb file.
Tip You can view the property settings for the .mxb file. Select the file in the Solution Explorer and view its properties in the Properties Window (View»Properties Window). |
Generating Code for a Visual C++ DAQmx Task Class
The DAQmx task class code is contained in a .h and .cpp file in the project. These files have the same base name as the .mxb file, but have different extensions for the header and source files.
The Measurement Studio Add-In monitors all changes to the .mxb file. When an .mxb file that is contained in a Visual C++ project is saved, the add-in causes the DAQ Assistant to generate the source code for the configuration that is stored in the .mxb file.
Refer to the NI Measurement Studio Help for more information about generating code and using a task in Measurement Studio.