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

Chapter 4 External Subroutines

Create the subroutine using the following command.

nmake /f sum.lvm

Solaris 1.x, Solaris 2.x, and HP-UX

Unbundled Sun C Compiler and HP-UX C/ANSI C Compiler

As described in the External Subroutine section of this chapter, you compile an external subroutine the same way you compile a CIN. The first step is to create the makefile for the subroutine using the shell script lvmkmf. You can then use the standard make command to make the subroutine code. For this example, enter the following command.

lvmkmf -t LVSB sum

This creates a file called Makefile. After executing lvmkmf, enter make, which uses the makefile to create a file called sum.lsb. CINs and other external subroutines can call this sum.lsb file.

Calling Code

The following example shows how to call an external subroutine. In this example, a CIN uses the external subroutine to calculate the mean of an array.

The diagram for the VI is shown in the following illustration. To avoid confusion, create the calling source code and makefiles in a directory separate from the external subroutine. Save the VI as calcmean.vi.

Save the .c file for the CIN as calcmean.c. The following is a listing of calcmean.c, with its CINRun routine filled in and the prototype for the sum external routine added.

/*

* CIN source file */

#include "extcode.h"

LabVIEW Code Interface Reference Manual

4-10

© National Instruments Corporation

Chapter 4 External Subroutines

/* stubs for advanced CIN functions */

UseDefaultCINInit

UseDefaultCINDispose

UseDefaultCINAbort

UseDefaultCINLoad

UseDefaultCINUnload

UseDefaultCINSave

/*

* typedefs */

typedef struct { int32 dimSize; float64 arg1[1]; } TD1;

typedef TD1 **TD1Hdl;

extern float64 sum(float64 *x, int32 n);

CIN MgErr CINRun(TD1Hdl xArray, float64 *mean);

CIN MgErr CINRun(TD1Hdl xArray, float64 *mean)

{

float64 *x, total; int32 n;

x = (*xArray)->arg1;

n = (*xArray)->dimSize; total = sum(x, n);

*mean = total/(float64)n; return noErr;

}

CINRun calculates the mean using the external subroutine sum to calculate the sum of the array. The external subroutine is declared with the keyword extern so that the code compiles even though the subroutine is not present.

© National Instruments Corporation

4-11

LabVIEW Code Interface Reference Manual

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