Getting Started with the NI LabVIEW™C Generator Use the LabVIEW C Generator to generate generic C code from VIs.The generated C code can run on most platforms.
Note Refer to the LabVIEW C Generator Readme,which is available by opening
readme_C_Generator.html on the NI LabVIEW C Generator CD,for system requirements
and instructions about installing the C Generator.
This manual contains a step-by-step tutorial that shows you how to generate C code from an exported VI and use that generated C code on a target.In this tutorial,you specify a VI to export for C code
generation,configure C code generation settings,define the function prototype for the exported VI,
generate C code,and use the generated C code on a non-LabVIEW target.The tutorial also describes
how to create and configure the generated C code so you can use it in the following commonly used
targets:
•A32-bit Windows platform(Win32)DLL created with the Microsoft Visual Studio compiler.
•A static library created in Cygwin using GNU Compiler Collection(GCC).
•An ARM application built in KeilµVision for a Luminary Micro EK-LM3S8962target.
Note You must configure some settings differently for each target.As you use this tutorial,
refer to the Win32DLL,Cygwin Static Library,and EK-LM3S8962Application sections of
this manual for target-specific instructions.
Contents
Installing Additional Third-Party Software (1)
Creating the LabVIEW Project (2)
Creating a Build Specification (2)
Creating a VI for C Code Generation (3)
Defining the Function Prototype (5)
Setting C Code Generation Options (7)
Testing the VI (7)
Generating C Code in LabVIEW (9)
Building the Generated C Code (11)
Win32DLL (11)
Cygwin Static Library (13)
EK-LM3S8962Application (15)
Where to Go from Here (16)
Installing Additional Third-Party Software
You must install the following third-party software based on the target on which you want to use the
generated C code:
•Win32DLL
–Microsoft Visual Studio2008compiler—Refer to the Microsoft Web site at
www.microsoft for more information about installing Microsoft Visual Studio.
–GNU Make for Windows—Refer to the Make for Windows Web site at
gnuwin32.sourceforge/packages/make.htm for more information about
installing the GNU Make utility.
•Cygwin Static Library
generated–Cygwin1.7.5or later—Refer to the Cygwin Web site win for more information about installing Cygwin.Install Cygwin with the following packages:
•binutils2.20.51or later
•gcc–g++3.4.4or later
•make3.81or later
•EK-LM3S8962Application
–RealView Microcontroller Development Kit,including KeilµVision3or later—Refer to the Keil Web site at www.keil for more information about installing KeilµVision. Creating the LabVIEW Project
Use LabVIEW projects(.lvproj)to group together LabVIEW files and non-LabVIEW files,create
build specifications for exporting VIs for C code generation,and generate C code.You must use a
LabVIEW project to generate C code.
Complete the following steps to create a project.
1.Launch LabVIEW.
2.Select File»New Project to display the Project Explorer window.
The Project Explorer window displays a new untitled project,which includes the My Computer
target.The Project Explorer window includes two pages,the Items page and the Files page.The
Items page displays the project items as they exist in the project tree.The Files page displays the
project items that have a corresponding file on disk.Project items on the Files page both reflect
and update the contents on disk.You can switch from one page to the other by clicking the Items
and Files tabs.
3.Right-click the untitled project in the Project Explorer window and select Save from the shortcut
menu.
4.In the Name the Project dialog box,enter GreatestCommonDivisor and select a location to
save the project file.
5.Click the OK button to save the project.
Creating a Build Specification
You use a build specification to specify how the C Generator generates C code for exported VIs.You
can have multiple build specifications under the same My Computer target.For example,if you want to generated C code from an exported VI for a Win32DLL and a Luminary Micro EK-LM3S8962target, you can create a separate build specification for each of these targets.
Complete the following steps to create the build specification.
1.In the Project Explorer window,right-click Build Specifications under My Computer and select
New»C Code Generation from the shortcut menu to create a C code generation build specification.
LabVIEW displays the C Code Generation Properties dialog box.
2.On the Information page of the C Code Generation Properties dialog box,enter Greatest
Common Divisor in the Build specification name text box to rename the build specification.
3.In the Destination directory text box,specify a location to save the generated C files.
Getting Started with LabVIEW C Generator2ni
(EK-LM3S8962Application)Set the value of the Destination directory option to
labview\examples\CGenerator\Tutorial\Keil–ARM LM3S8962.The C Generator
installs an exampleµVision project(.Uv2)you will use in this tutorial to build the generated C
code into an ARM application.TheµVision project includes the generated C code from this location.
4.Verify that the Information page appears similar to the following figure.
Figure1.Defining the Build Specification Information
5.Click the OK button to close the build specification.
6.LabVIEW displays a dialog box to notify you that you have not selected a VI to export.Click the
Yes button.
7.Save the project.
Creating a VI for C Code Generation
After you create a LabVIEW project and C code generation build specification,you can create a new
VI or add an existing VI to the project.This tutorial uses an existing example VI,Greatest Common Divisor.vi,which is installed with the C Generator.
Complete the following steps to add the VI to the project.
1.In the Project Explorer window,right-click My Computer and select Add»File from the shortcut
menu.
Note You must include the VI you want to generate C code for under My Computer.
You cannot generate C code from any other targets in the Project Explorer window.©National Instruments Corporation3Getting Started with LabVIEW C Generator
2.In the Select a File to Insert dialog box,navigate to
labview\examples\CGenerator\Tutorial\Greatest Common Divisor.vi.Click the
Add File button.The VI appears under My Computer,as shown in the following figure.
Figure2.Adding the VI to the Project
3.Save the project.
4.Open the VI and view the block diagram,which is shown in the following figure.
Figure3.Viewing the Greatest Common Divisor.vi Block Diagram
Getting Started with LabVIEW C Generator4ni
The Greatest Common Divisor.vi computes the greatest common divisor between two numbers.
Tip When you create a new VI to export for C code generation,you must account for differences
in VIs you develop to run as LabVIEW applications and VIs you develop for C code generation.
Exported VIs and all VIs in their hierarchies support some block diagram objects differently
from VIs running as LabVIEW applications.Refer to Developing VIs for C Code Generation
in the LabVIEW Help for more information about these differences.Select Help»LabVIEW
Help to search the LabVIEW Help.
Defining the Function Prototype
Use the build specification to specify which VI you want to export for C code generation and to define the function prototype that the C Generator generates for that VI.
Complete the following steps to define the function prototype.
1.Double-click the Greatest Common Divisor build specification in the Project Explorer window
to display the C Code Generation Properties dialog box.
2.Select Source Files from the Category list in the C Code Generation Properties dialog box to
display the Source Files page.
3.From the Project Files tree,select GreatestCommonDivisor.vi and click the Add Item arrow
button next to the Exported VI listbox to specify the VI you want to export for C code generation,
as shown in the following figure.
Figure4.Specifying a VI to Export for C Code Generation
©National Instruments Corporation5Getting Started with LabVIEW C Generator
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论