Application Note 182 Programming for the LabVIEW Real-Time Module Using LabWindows/CVI Introduction This document discusses using LabWindows/CVI to interface with RT Series hardware and to write DLLs to use in LabVIEW VIs for downloading onto an RT device. What Is the LabVIEW Real-Time Module? The LabVIEW Real-Time Module is a LabVIEW add-on that downloads LabVIEW applications onto embedded hardware for deterministic real-time performance. You can debug these applications using the traditional LabVIEW development environment under Windows and then download the applications to run under a real-time operating system embedded on RT Series processor-based measurement hardware. How Does LabWindows/CVI Extend This Capability? LabWindows/CVI extends the real-time functionality of LabVIEW to C programmers in two ways. First, LabWindows/CVI offers programmatic access to the shared memory of an RT Series Plug-In DAQ device through reading and writing functions. Second, in LabWindows/CVI you can build DLLs that can be downloaded and run on any RT Series device. Note In both cases, you must have the LabVIEW Real-Time Module installed on the machine being used. For accessing shared memory, no knowledge of LabVIEW is required. However, using a DLL for downloading to a device requires the LabVIEW development environment. Accessing Shared Memory The cvirtsup.fp driver, located in the toolslib\cvirtsup directory, contains the functionality for accessing the shared memory of an RT Series DAQ device. You can use the functions to read and write data to and from the shared memory of the RT Series DAQ device defined in the device field. This device number is the number used by Measurement & Automation Explorer (MAX) to refer to the device. Reading and writing data to the shared memory, you can pass information between programs running on the RT Series DAQ device and those running on the host computer. When you use LabWindows/CVI and the cvirtsup.fp functions to access the shared memory, note that C code is not actually downloaded to the device itself. Only the shared memory is accessed. Refer to lvrtsamp.prj in samples\cvirtsup for an example. LabVIEW, National Instruments, and ni.com are trademarks of National Instruments Corporation. Product and company names mentioned herein are trademarks or trade names of their respective companies. For patents covering National Instruments products, refer to the appropriate location: Help»Patents in your software, the patents.txt file on your CD, or ni.com/patents. 342227A-01 2002 National Instruments Corporation. All rights reserved. January 2002
LabWindows/CVI LabVIEW Real-Time Support Engine LabWindows/CVI has three different versions of its run-time engine: Standard Run-Time Engine, which handles all LabWindows/CVI functionality Instrument Support Engine, which removes much of the UI capabilities of LabWindows/CVI, but retains most of the remaining functionality LabVIEW Real-Time Support Engine, which provides the functionality of the embedded RT Series devices. When you design a DLL in LabWindows/CVI to use in a real-time LabVIEW application, build the DLL with this engine to ensure that your final DLL is compatible with the LabVIEW Real-Time Module and can be downloaded and executed on an RT Series device. Creating DLLs for Use with the LabVIEW Real-Time Module You can use LabWindows/CVI DLLs with the LabVIEW Real-Time Module in two ways: Use legacy C code and update the code to compile and link using the LabWindows/CVI LabVIEW Real-Time Support Engine instead of rewriting the code in LabVIEW. Write portions of your application in LabWindows/CVI, compile, and link the code into a DLL using the LabWindows/CVI LabVIEW Real-Time Support Engine. In both cases, you can then use the Call Library Function Node in LabVIEW to link your DLL into a downloadable LabVIEW application. Building a LabWindows/CVI DLL for the LabVIEW Real-Time Module Once you design and implement the code for the DLL, you can create a DLL by setting the Build»Target Type to Dynamic Link Library and switching the Runtime Support field of the Target Settings dialog box to LabVIEW Real-Time Only. You can leave all other fields in their default state. Click the Help button for more information on building a DLL. Refer to lvrt_vi.prj in samples\cvirtsup for an example. Using Your DLL with the LabVIEW Real-Time Module In a real-time LabVIEW application, you can use a Call Library Function Node in LabVIEW to access functions exported by the DLL. Call Library Function Node You can use a Call Library Function Node, an element of LabVIEW, to make calls to exported DLL functions. You can use a Call Library Function Node, which accepts a large number of data types and calling conventions, to call functions from most standard and custom libraries. Under Windows, you can call a DLL function directly. Under Mac OS and UNIX, you can call a shared library function directly. In setting up a Call Library Function Node, you specify the input and output parameters, data types, and return value. With your specifications, you can pass data and error information between LabVIEW and the DLL. For more information about using a Call Library Function Node, refer to LabVIEW Help. Application Note 182 2 ni.com
Downloading a LabVIEW Real-Time Module Application to an RT Series Device After creating your LabVIEW Real-Time Module application and using Call Library Function Nodes to reference your DLL, you are ready to download the program onto the RT Series device. To download your LabVIEW Real-Time Module application, you must have an RT Series device either installed on your computer or connected accross the network. In LabVIEW, select Operation»Switch Execution Target, and change the execution target to be your RT Series device. After resetting LabVIEW, select Operate»Download Application to download the LabVIEW application and all DLLs linked to it through Call Library Function Nodes. Once you download your application, you can execute it as you do other LabVIEW applications, although your application is running on the RT Series device and not on the host computer. For more information about downloading LabVIEW Real-Time Module applications and their execution on an RT Series device, please refer to the LabVIEW Real-Time Help. Debugging under the LabVIEW Real-Time Module The LabVIEW Real-Time Module has the standard debugging features of LabVIEW but cannot step inside the code of Call Library Function Nodes. Under LabWindows/CVI, DLLs created using the LabVIEW Real-Time Support Engine do not contain debugging information, because the user protection features required to debug an application in LabWindows/CVI cannot execute in an embedded RT Series device. National Instruments recommends that you debug your LabWindows/CVI DLLs prior to creating your final DLLs for the LabVIEW Real-Time Module. An alternative to step-through debugging is to put return error codes and/or return error strings in the interface to the functions exported from the DLL. You can check these return values for error messages to determine where an error might have occurred and how to fix it. LabWindows/CVI Functionality in the LabVIEW Real-Time Module LabWindows/CVI Run-Time Libraries LabWindows/CVI restricts its available functionality to what is compatible with the real-time operating system on embedded RT Series devices. The LabWindows/CVI LabVIEW Real-Time Support Engine 6.0 supports a subset of ANSI C, Formatting and I/O, and Utility Library functions. LabWindows/CVI also has libraries, such as the NI-DAQ library, which are compatible with RT Series devices. Other libraries, such as Easy I/O library and the LabWindows/CVI User Interface (UI) library, are not applicable on RT Series devices. For a complete list of the ANSI C, Formatting and I/O, and Utility Library functions exported by LabWindows/CVI for use with the LabVIEW Real-Time Module, type cvi_lvrt.dll in the index tab of the LabWindows/CVI Help. National Instruments Corporation 3 Application Note 182
DAQ Functionality The LabWindows/CVI development environment offers the data acquisition and easy I/O for DAQ libraries. Currently, only the function calls from the LabWindows/CVI data acquisition library are available to the LabVIEW Real-Time Module. Function calls from the easy I/O for DAQ library are not available. PID Functionality The PID toolkit also is available for use in the LabVIEW Real-Time Module. Interfaces between the LabVIEW Real-Time Module, LabWindows/CVI, and Remote Computers LabWindows/CVI Applications for Use with RT Series Devices A LabWindows/CVI program can exchange data between a host PC and a RT Series DAQ device using the shared memory and the functions contained in the cvirtsup.fp instrument driver. Data can be written to and read from the shared memory and the data received can be used within the LabWindows/CVI application. No restrictions exist on communication between your LabWindows/CVI program and other applications. You can transmit any data received from the shared memory of the RT Series device to other applications using any of the communication protocols available in LabWindows/CVI. Also, because the program is not actually running on the RT Series device, you can continue to use the UI Library panels. Real-Time LabVIEW Applications Using LabWindows/CVI DLLs You can pass data to and from the DLL using the function parameters and return values of the functions called using a Call Library Function Node. You can transfer this data, once returned to LabVIEW, to other applications and remote computers using LabVIEW data transfer protocols. You also can use LabVIEW User Interface front panels to show data. You can implement Ethernet connections between RT Series devices on the same network using the LabVIEW TCP/IP interfaces. You can find examples of how to use these interfaces in examples\rt directory. Currently, DataSocket and UDP are not available for embedded RT Series devices. Hardware and Controllers for Real-Time Applications LabVIEW Real-Time systems can incorporate DAQ, CAN, Serial, Motion, and DSA devices but not Instrument devices. For a detailed list, refer to the LabVIEW Real-Time Help. LabVIEW Real-Time systems support the following PXI RT Series controllers: PXI 8145 RT, PXI 8146 RT, PXI 8156B RT, PXI 8170 RT, PXI 8175 RT, and PXI 8176 RT. Performance Comparisons While running on the embedded RT Series device, a real-time LabVIEW application performs function calls to DLLs loaded in the memory of the RT Series device. Therefore, function calls to LabWindows/CVI DLLs are equivalent to calls to LabVIEW VIs, yielding no decrease in performance. Application Note 182 4 ni.com
Examples You can find LabWindows/CVI examples of the shared memory access and DLL creation for use in a LabVIEW real-time application in the samples\cvirtsup directory. You can find real-time examples of Ethernet, TCP/IP connections, and PID and DAQ controls in the examples\rt directory. National Instruments Corporation 5 Application Note 182
*342227A-01* 342227A-01 Jan02