Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Labview Code Interface Reference Manual.pdf
Скачиваний:
33
Добавлен:
29.05.2015
Размер:
1.13 Mб
Скачать

 

Chapter

CIN Advanced Topics

3

 

This chapter covers several topics that are needed only in advanced applications, including how to use the CINInit, CINDispose,

CINAbort, CINLoad, CINUnload, and CINSave routines. The chapter also discusses how global data works within CIN source code, and how users of Windows 3.1, Windows 95, and Windows NT can call a DLL from a CIN.

CIN Routines

A CIN consists of several routines, as described by the .c file that LabVIEW creates when you select Create .c File... from the CIN popup menu. The previous chapters have discussed only the CINRun routine. The other routines are CINLoad, CINInit, CINAbort,

CINSave, CINDispose, and CINUnload.

It is important to understand that for most CINs, you need to write only the CINRun routine. The other routines are supplied mainly for the cases in which you have special initialization needs, such as when your CIN is going to maintain some information across calls, and you want to preallocate or initialize global state information.

In the case where you want to preallocate/initialize global state information, you first need to understand more of how LabVIEW manages data and CINs.

Data Spaces and Code Resources

When you create a CIN, you compile your source into an object code file and load the code into the node. At that point, LabVIEW loads a copy of the code (called a code resource) into memory and attaches it to the node. When you save the VI, this code resource is saved along with the VI as an attached component; the original object code file is no longer needed.

When LabVIEW loads a VI, it allocates a data space, a block of data storage memory, for that VI. This data space is used, for instance, to store the values in shift registers. If the VI is reentrant, then LabVIEW

© National Instruments Corporation

3-1

LabVIEW Code Interface Reference Manual

Chapter 3 CIN Advanced Topics

allocates a data space for each usage of the VI. See Chapter 26,

Understanding How LabVIEW Executes VIs, in your LabVIEW User Manual for more information on reentrancy.

Within your CIN code resource, you may have declared global data. Global data includes variables that are declared outside of the scope of all routines, and, for the purposes of this discussion, variables that are declared as static variables within routines. LabVIEW allocates space for this global data. As with the code itself, there is always only one instance of these globals in memory. Regardless of how many nodes reference the code resource and regardless of whether the surrounding VI is reentrant, there is only one copy of these globals in memory, and their values are consistent.

When you create a CIN node, LabVIEW allocates a CIN data space, a 4-byte storage location in the VI data space(s), strictly for the use of the CIN node. Each CIN may have one or more CIN data spaces reserved for the node, depending on how many times the node appears in a VI or collection of VIs. You can use this CIN data space to store global data on a per data space basis, as described in the Code Globals and CIN Data Space Globals section later in this chapter.

VI

global storage

VI data space

code resource

(for code globals)

4-byte CIN data space

(for data space globals)

Figure 3-1. Data Storage Spaces for One CIN, Simple Case

LabVIEW Code Interface Reference Manual

3-2

© National Instruments Corporation

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