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

Chapter 4 Programming Issues for CINs

bElmtp[l*cos + j]; resultElmtp++;

}

out:

return err;

}

In this example, CINRun is the only routine performing substantial operations. CINRun cross-multiplies the two-dimensional arrays A and B. LabVIEW stores the resulting array in resulth. If the number of columns in A is not equal to the number of rows in B, CINRun sets *error to LVTRUE to inform the calling diagram of invalid data.

SetCINArraySize, the LabVIEW routine that accounts for alignment and padding requirements, resizes the array. The two-dimensional array data structure is the same as the one-dimensional array data structure, except the 2D array has two dimension fields instead of one. The two dimensions indicate the number of rows and the number of columns in the array, respectively. The data is declared as a one-dimensional C-style array. LabVIEW stores data row by row, as shown in the following illustration.

For an array with r rows and c columns, you can access the element at row i and column j as shown in the following code.

value = (*arrayh)–>arg1[i*c + j];

Working with Clusters

To take an array of clusters and a single cluster as inputs, complete the following steps. The clusters contain a signed 16-bit integer and a string. The input for the array of clusters is an input-output terminal. In addition to the array of clusters, the CIN returns a Boolean parameter and a signed

Using External Code in LabVIEW

4-18

www.ni.com

Chapter 4 Programming Issues for CINs

32-bit integer. If the cluster value is already present in the array of clusters, the CIN sets the Boolean parameter to TRUE and returns the position of the cluster in the array of clusters using the 32-bit integer output. If the cluster value is not present, the CIN adds it to the array, sets the Boolean output to FALSE, and returns the new position of the cluster in the array of clusters.

This example shows only the front panel, block diagram, and source code.

1.To create the CIN, follow the instructions in the Creating a CIN section in Chapter 3, CINs.

The front panel for this VI is shown in the following illustration.

The block diagram for this VI is shown in the following illustration.

2.Save the VI as tblsrch.vi.

3.Save the .c file for the CIN as tblsrch.c. Following is the source code for tblsrch.c with the CINRun routine added.

/*

* CIN source file */

#include "extcode.h" #define ParamNumber 0

/* The array parameter is parameter 0 */

/*

* typedefs */

© National Instruments Corporation

4-19

Using External Code in LabVIEW

Chapter 4 Programming Issues for CINs

typedef struct { int16 number; LStrHandle string;

}TD2; typedef struct {

int32 dimSize; TD2 arg1[1];

}TD1;

typedef TD1 **TD1Hdl;

 

CIN MgErr CINRun(

 

 

TD1Hdl

clusterTableh,

 

TD2

*elementp,

 

LVBoolean

*presentp,

 

int32

*positionp);

CIN MgErr CINRun(

 

 

TD1Hdl

clusterTableh,

 

TD2

*elementp,

 

LVBoolean

*presentp,

 

int32

*positionp) {

int32

size,i;

 

MgErr

err=noErr;

 

TD2

*tmpp;

 

LStrHandle

newStringh;

 

TD2

*newElementp;

 

int32

newNumElements;

size = (*clusterTableh)–>dimSize; tmpp = (*clusterTableh)–>arg1; *positionp = –1;

*presentp = LVFALSE; for(i=0; i<size; i++) {

if(tmpp–>number == elementp–>number) if(LStrCmp(*(tmpp–>string),

*(elementp–>string)) == 0) break;

tmpp++;

}

if(i<size) { *positionp = i; *presentp = LVTRUE; goto out;

}

newStringh = elementp–>string;

Using External Code in LabVIEW

4-20

www.ni.com

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