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

Chapter 5 Advanced Applications

actually loaded into memory, and both references point to the same code. However, LabVIEW can verify that a subVI call matches the subVI connector pane terminal, but LabVIEW cannot verify that your source code matches the CIN call.

One Reference to the CIN in a Single VI

The following section describes the standard case, in which you have a code resource referenced by only one CIN, and the VI containing the CIN is non-reentrant. The other cases have slightly more complicated behavior, described in later sections of this chapter.

Loading a VI

When you first load a VI, LabVIEW calls the CINLoad routines for any CINs contained in that VI. This gives you a chance to load any file-based resources at load time, because LabVIEW calls this routine only when the VI is first loaded. Refer to the Loading a New Resource into the CIN section that follows for an exception to this rule. After LabVIEW calls the CINLoad routine, it calls CINInit. Together, these two routines perform any initialization you need before the VI runs.

LabVIEW calls CINLoad once for a given code resource, regardless of the number of data spaces and the number of references to that code resource. For this reason, you should initialize code globals in CINLoad.

LabVIEW calls CINInit for a given code resource a total of one time for each CIN data space multiplied by the number of references to the code resource in the VI corresponding to that data space. If you want to use CIN data space globals, initialize them in CINInit. Refer to the

Code Globals and CIN Data Space Globals, Loading a New Resource into the CIN, and Compiling a VI sections later in this chapter for more information.

Unloading a VI

When you close a VI front panel, LabVIEW checks whether any references to that VI are in memory. If so, the VI code and data space remain in memory. When all references to a VI are removed from memory and its front panel is not open, that VI is unloaded from memory.

When a VI is unloaded from memory, LabVIEW calls the CINDispose routine, giving you a chance to dispose of anything

you allocated earlier. CINDispose is called for each CINInit call. For instance, if you used XXNewHandle in your CINInit routine, you should

© National Instruments Corporation

5-3

Using External Code in LabVIEW

Chapter 5 Advanced Applications

use XXDisposeHandle in your CINDispose routine. LabVIEW calls CINDispose for a code resource once for each individual CIN data space.

As the last reference to the code resource is removed from memory, LabVIEW calls the CINUnload routine for that code resource once, giving you the chance to dispose of anything allocated in CINLoad.

As with CINDispose/CINInit, CINUnload is called for each CINLoad. For example, if you loaded some resources from a file in CINLoad, you can free the memory those resources are using in CINUnload. After LabVIEW calls CINUnload, the code resource itself is unloaded from memory.

Loading a New Resource into the CIN

If you load a new code resource into a CIN, the old code resource is first given a chance to dispose of anything it needs to dispose. LabVIEW calls CINDispose for each CIN data space and each reference to the code resource, followed by the CINUnload for the old resource. The new code resource is then given a chance to perform any initialization it needs to perform. LabVIEW calls the CINLoad for the new code resource, followed by the CINInit routine, called once for each data space and each reference to the code resource.

Compiling a VI

When you compile a VI, LabVIEW recreates the VI data space, including resetting all uninitialized shift registers to their default values. In the same way, your CIN is given a chance to dispose or initialize any storage it manages. Before disposing of the current data space, LabVIEW calls the CINDispose routine for each reference to the code resource within the VI(s) being compiled to give the code resource a chance to dispose of any old results it is managing. LabVIEW then compiles the VI and creates a new data space for the VI(s) being compiled (multiple data spaces for any reentrant VI). LabVIEW then calls CINInit for each reference to the code resource within the compiled VI(s) to give the code resource a chance to create or initialize any data it wants to manage.

Running a VI

Click the Run button in a VI to run the VI. When LabVIEW encounters a

Code Interface Node, it calls the CINRun routine for that node.

Saving a VI

When you save a VI, LabVIEW calls the CINSave routine for that VI, giving you the chance to save any resources, such as something you loaded

Using External Code in LabVIEW

5-4

www.ni.com

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