Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Using External Code in LabVIEW.pdf
Скачиваний:
49
Добавлен:
29.05.2015
Размер:
1.85 Mб
Скачать

Chapter 1

Introduction

(Macintosh) Use the Apple Event VIs. Apple Events are a Macintosh-specific protocol through which applications communicate with each other. You can use them to send commands between applications or to launch other applications. If you are a LabVIEW user, refer to the Using Apple Events and the PPC Toolbox to Communicate with LabVIEW Applications on the Macintosh Application Note for information about different methods for using Apple Event VIs to launch and control other applications.

Characteristics of the Two Calling Approaches

Note In most cases, Call Library Function is easier to use than a Code Interface Node.

The LabVIEW Call Library Function and the Code Interface Node (CIN) are block diagram objects that link source code written in a conventional programming language to LabVIEW. They appear on the block diagram as icons with input and output terminals. Linking external code to LabVIEW includes the following steps:

1.You compile the source code and link it to form executable code. If you already have a compiled DLL, this step is not necessary.

2.LabVIEW calls the executable code when the node executes.

3.LabVIEW passes input data from the block diagram to the executable code.

4.LabVIEW returns data from the executable code to the block diagram.

The LabVIEW compiler can generate code fast enough for most programming tasks. Call CINs and shared libraries from LabVIEW to accomplish tasks a text-based language can accomplish more easily, such as time-critical tasks. Also use CINs and shared libraries for tasks you cannot perform directly from the block diagram, such as calling system routines for which no corresponding LabVIEW functions exist. CINs and shared libraries also can link existing code to LabVIEW, although you might need to modify the code so it uses the correct LabVIEW data types.

CINs and shared libraries execute synchronously, so LabVIEW cannot use the execution thread used by these objects for any other tasks. When a VI runs, LabVIEW monitors the user interface, including the menus and keyboard. In multithreaded applications, LabVIEW uses a separate thread for user interface tasks. In single-threaded applications, LabVIEW switches between user interface tasks and running VIs.

Using External Code in LabVIEW

1-2

www.ni.com

Chapter 1

Introduction

When CIN or shared library object code executes, it takes control of its execution thread. If an application has only a single thread of control, the application waits until the object code returns. In single-threaded operating systems such as Macintosh, these objects even prevent other applications from running.

LabVIEW cannot interrupt object code that is running, so you cannot reset a VI that is running a CIN or shared library until execution completes. If you want to write a CIN or shared library that performs a long task, be aware that LabVIEW cannot perform other tasks in the same thread while these objects executes.

Details of Call Library Function

You can call most standard shared libraries with Call Library Function. In Windows these libraries are DLLs, on the Macintosh they are Code Fragments, and on UNIX they are Shared Libraries. Call Library Function includes a large number of data types and calling conventions. You can use it to call functions from most standard and custom-made libraries.

Call Library Function is most appropriate when you have existing code you want to call, or if you are familiar with the process of creating standard shared libraries. Because a library uses a format standard among several development environments, you can use almost any development environment to create a library that LabVIEW can call. Refer to the documentation for your compiler to determine whether you can create standard shared libraries. Refer to the Chapter 2, Shared Libraries (DLLs), for more information about Call Library Function.

Details of a CIN

The CIN is a general method for calling C code from LabVIEW. You can pass arbitrarily complex data structures to and from a CIN. In some cases, you might have higher performance using CINs because data structures pass to the CIN in the same format that they are stored in LabVIEW.

In some cases, you might want a CIN to perform additional tasks at certain execution times. For example, you might want to initialize data structures at load time or free private data structures when the user closes the VI containing the CIN. For these situations, you can write routines that LabVIEW calls at predefined times or when the node executes. Specifically, LabVIEW calls certain routines when the VI containing the CIN is loaded, saved, closed, aborted, or compiled. You

generally use these routines in CINs that perform an ongoing task, such as accumulating results from call to call, so you can allocate, initialize,

© National Instruments Corporation

1-3

Using External Code in LabVIEW

Chapter 1

Introduction

and deallocate resources at the correct time. Most CINs perform a specific action at run-time only.

To create a CIN, you must be an experienced C developer. Also, because CINs are tightly coupled with LabVIEW, there are restrictions on which compilers you can use.

After you write your first CIN as described in this manual, writing new CINs is relatively easy. The work involved in writing new CINs is mostly in coding the algorithm, because the interface to LabVIEW remains the same, regardless of the development system.

Using External Code in LabVIEW

1-4

www.ni.com

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]