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

Chapter 3

CINs

Step 2. Wire the Inputs and Outputs to the CIN

Connect wires to all the terminal pairs on the CIN to specify the data you want to pass to the CIN, and the data you want to receive from the CIN. The order of terminal pairs on the CIN corresponds to the order in which parameters are passed to the code. You can use any LabVIEW data types as CIN parameters, so you can pass arbitrarily

complex hierarchical data structures, such as arrays containing clusters that can in turn contain other arrays or clusters to a CIN. Refer to the Passing Parameters section in Chapter 4, Programming Issues for CINs, for information about how LabVIEW passes parameters of specific data types to CINs.

Step 3. Create a .c File

Right-click the node and select Create .c File to create a .c file in the style of the C programming language. The .c file describes the routines you must write and the data types for parameters that pass to the CIN.

For example, consider the following call to a CIN, which takes a 32-bit integer as an input and returns a 32-bit integer as an output.

The following code excerpt is the initial .c file for this node. You can write eight routines for the CIN. The CINRun routine is required and the others are optional. If an optional routine is not present, LabVIEW uses a default routine when building the CIN.

/*

* CIN source file */

#include "extcode.h"

CIN MgErr CINRun(int32 *num_in, int32 *num_out);

CIN MgErr CINRun(int32 *num_in, int32 *num_out) {

/* ENTER YOUR CODE HERE */ return noErr;

}

This .c file is a template in which you must write C code. extcode.h is automatically included, because it defines basic data types and a number of routines that can be used by CINs. extcode.h also defines some constants

Using External Code in LabVIEW

3-6

www.ni.com

Chapter 3

CINs

and types whose definitions may conflict with the definitions of system header files. The cintools directory also contains hosttype.h, which resolves these differences. This header file also includes many of

the common header files for a given platform.

Always use #include "extcode.h" at the beginning of your source code. If your code needs to make system calls, also use #include "hosttype.h" immediately after #include "extcode.h", and then include your system header files. hosttype.h includes only a subset of the .h files for a given operating system. If the .h file you need is not included by hosttype.h, you can include it in the .c file for your CIN after you include hosttype.h.

LabVIEW calls the CINRun routine when it is time for the node to execute. CINRun receives the input and output values as parameters. The other routines (CINLoad, CINSave, CINUnload, CINAbort, CINInit,

CINDispose, and CINProperties) are housekeeping routines, called at specific times so you can take care of specialized tasks with your CIN. For example, LabVIEW calls CINLoad when it first loads a VI. If you need to accomplish a special task when your VI loads, put the code for that task in the CINLoad routine. To do so, write your CINLoad routine as follows:

CIN MgErr CINLoad(RsrcFile reserved) {

Unused (reserved);

/* ENTER YOUR CODE HERE */ return noErr;

}

In general, you only need to write the CINRun routine. Use the other routines when you have special initialization needs, such as when your CIN must maintain some information across calls, and you want to preallocate or initialize global state information. The following code shows an example of how to fill out the CINRun routine from the previously shown LabVIEW-generated .c file to multiply a number by two. Refer to the

Passing Parameters section in Chapter 4, Programming Issues for CINs, for information about how LabVIEW passes data to a CIN, with several examples.

CIN MgErr CINRun(int32 *num_in, int32 *num_out) {

*num_out = *num_in * 2;

return noErr;

}

© National Instruments Corporation

3-7

Using External Code in LabVIEW

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