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

Chapter 2 CIN Parameter Passing

running VI, LabVIEW can possibly free enough memory to continue running correctly.

Examples with Scalars

The following examples show the steps for creating CINs and how to work with scalar data types. Chapter 5, Manager Overview, contains more examples.

Steps for Creating a CIN That Multiplies Two Numbers

Consider a CIN that takes two single-precision floating-point numbers and returns their product.

1.Place the CIN on the Block Diagram

2.Add Two Input and Output Terminals to the CIN

3.Wire the Inputs and Outputs to the CIN

Place two single-precision numeric controls and one single-precision numeric indicator on a front panel. Wire the node as shown in the following illustration. Notice that A*B is wired to an output-only terminal pair.

Save the VI as mult.vi.

4. Create the CIN Source Code

Select Create .c File... from the CIN node pop-up menu. LabVIEW prompts you to select a name and a storage location for a .c file. Name the file mult.c. LabVIEW creates a .c file shown in the following listing.

LabVIEW Code Interface Reference Manual

2-4

© National Instruments Corporation

Chapter 2 CIN Parameter Passing

/*

* CIN source file */

#include "extcode.h"

/* stubs for advanced CIN functions */

UseDefaultCINInit

UseDefaultCINDispose

UseDefaultCINAbort

UseDefaultCINLoad

UseDefaultCINUnload

UseDefaultCINSave

CIN MgErr CINRun (float32 *A, float32 *B, float32 *A_B);

CIN MgErr CINRun (float32 *A, float32 *B, float32 *A_B) {

/* ENTER YOUR CODE HERE */

return noErr;

}

This .c file contains a prototype and a template for the CIN’s CINRun routine. The UseDefault... macros shown in the preceding example code take the place of the corresponding CIN routines. LabVIEW calls the CINRun routine when the CIN executes. In this example, LabVIEW passes CINRun the addresses of the three 32-bit floating-point numbers. The parameters are listed left to right in the same order as you wired them (top to bottom) to the CIN. Thus, A, B, and A_B are pointers to A, B, and A*B, respectively.

As described in the CIN .c File section of this chapter, the float32 data type is not a standard C data type. When LabVIEW creates a .c file, it gives unambiguous names for data types. For most C compilers, the float32 data type corresponds to the float data type. However, this may not be true in all cases, because the C standard does not define the sizes for the various data types. You can use these LabVIEW data types in your code because extcode.h associates these data types

© National Instruments Corporation

2-5

LabVIEW Code Interface Reference Manual

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