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

Chapter 5 Advanced Applications

VI

global storage

 

 

 

 

(code globals)

VI data space

code resource

 

 

 

 

 

 

 

4-byte CIN

 

 

 

 

 

data space

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

4-byte CIN

 

 

 

 

 

data space

 

 

 

 

 

 

 

 

 

 

 

4-byte CIN

 

 

 

 

 

data space

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

(data space globals)

 

 

 

Multiple References to the Same CIN in Different VIs

Making multiple references to the same CIN in different VIs is different for single-threaded operating systems than for mutlithreaded

operating systems. To use multithreading, you must use LabVIEW on Windows or Solaris 2.x.

Single-Threaded Operating Systems

When you make a VI reentrant, LabVIEW creates a separate data space for each instance of that VI. If you have a CIN data space in a reentrant VI and you call that VI in seven places, LabVIEW allocates memory to store seven CIN data spaces for that VI, each of which contains a unique storage location for the CIN data space for that calling instance.

As with multiple instances of the same node, LabVIEW calls the CINInit,

CINDispose, and CINAbort routines for each individual CIN data space.

If you have a reentrant VI containing multiple copies of the same code resource, LabVIEW calls the CINInit, CINDispose, and CINAbort routines once for each use of the reentrant VI, multiplied by the number of references to the code resource within that VI.

Using External Code in LabVIEW

5-6

www.ni.com

Chapter 5 Advanced Applications

The following illustration shows an example of three VIs referencing a reentrant VI containing one CIN.

caller 1

caller 2

caller 3

 

My VI

My VI

 

 

My VI

data space 1

 

 

 

 

data space 3

 

 

 

 

 

 

 

 

 

 

 

4-byte CIN

 

 

 

 

 

 

4-byte CIN

 

 

data space

 

 

 

 

 

 

data space

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

(data space globals)

 

 

 

(data space globals)

 

My VI

code resource

 

global storage

data space 2

 

 

 

 

 

 

 

 

 

 

 

 

4-byte CIN

 

 

 

 

 

 

 

 

 

data space

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

(data space globals)

 

 

 

 

(code globals)

Multithreaded Operating Systems

By default, CINs written before LabVIEW 5.0 run in a single thread, the user interface thread. When you change a CIN to be reentrant (that is, to run in multiple threads), more than one execution thread can call the CIN at the same time. If you want a CIN to run in the current execution thread of the block diagram, add the following code to your .c file:

CIN MgErr CINProperties(int32 mode, void *data)

{

switch (mode) {

case kCINIsReentrant: *(Bool32 *)data = TRUE; return noErr;

break;

}

return mgNotSupported;

}

© National Instruments Corporation

5-7

Using External Code in LabVIEW

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