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

Chapter 4 Programming Issues for CINs

Note LabVIEW 4.x stored Boolean arrays in memory as a series of bits packed to

the nearest 16-bit word. LabVIEW 4.x ignored unused bits in the last word. LabVIEW 4.x ordered the bits from left to right; that is, the most significant bit (MSB) is index 0. As with other arrays, a 4-byte dimension size preceded Boolean arrays. The dimension size for LabVIEW 4.x Boolean arrays indicates the number of valid bits contained in the array.

Paths

The exact structure for Path data types is subject to change in future versions of LabVIEW. A Path is a dynamic data structure LabVIEW passes the same way it passes arrays. LabVIEW stores the data for Paths in an application zone handle. Refer to Refer to Chapter 6, Function Descriptions, for more information about the functions that manipulate

Paths.

Clusters Containing Variably Sized Data

For cluster arguments, LabVIEW passes a pointer to a structure containing the elements of the cluster. LabVIEW stores scalar values directly as components inside the structure. If a component is another cluster, LabVIEW stores this cluster value as a component of the main cluster. If a component is an array or string, LabVIEW stores a handle to the array or string component in the structure.

Resizing Arrays and Strings

To resize return arrays and strings you pass to a CIN, use the LabVIEW SetCINArraySize routine. Pass to the function the handle you want to resize, information describing the data structure, and the desired size of the array or handle. The function takes into account any padding and alignment needed for the data structure. However, the function does not update the dimension fields in the array. If you successfully resize the array, you need to update the dimension fields to correctly reflect the number of elements in the array.

You can resize numeric arrays more easily with NumericArrayResize. Pass to this function the array you want to resize, a description of the data structure, and information about the new size of the array.

© National Instruments Corporation

4-9

Using External Code in LabVIEW

Chapter 4 Programming Issues for CINs

When you resize arrays of variably sized data (for example, arrays of strings) with the SetCINArraySize or NumericArrayResize routines, consider the following issues:

If the new size of the array is smaller, LabVIEW disposes of the handles used by the disposed element. Neither function sets the dimension field of the array. You must do this in your code after the function call.

If the new size of the array is larger, LabVIEW does not automatically create the handles for the new elements. You have to create these handles after the function returns.

The following sections describe the SetCINArraySize and

NumericArrayResize routines.

Using External Code in LabVIEW

4-10

www.ni.com

Chapter 4 Programming Issues for CINs

SetCINArraySize

MgErr SetCINArraySize (UHandle dataH, int32 paramNum, int32 newNumElmts);

Purpose

SetCINArraySize resizes a data handle based on the data structure of an argument you pass to the CIN. It does not set the array dimension field.

Parameters

Name

Type

Description

 

 

 

 

 

 

dataH

UHandle

Handle you want to resize.

 

 

 

paramNum

int32

Number for this parameter in the argument

 

 

list to the CIN. The leftmost parameter has a

 

 

parameter number of 0, and the rightmost

 

 

has a parameter number of n – 1, where n is

 

 

the total number of parameters.

 

 

 

newNumElmts

int32

New number of elements to which the handle

 

 

should refer. For a one-dimensional array

 

 

of five values, pass a value of 5. For a

 

 

two-dimensional array of two rows by

 

 

three columns, pass a value of 6.

 

 

 

Return Value

MgErr, which can contain the errors in the following list. Refer to the Manager Overview section later in this chapter for more information about MgErr.

noErr

No error.

mFullErr

Not enough memory to perform operation.

mZoneErr

Handle is not in specified zone.

© National Instruments Corporation

4-11

Using External Code in LabVIEW

Chapter 4 Programming Issues for CINs

NumericArrayResize

MgErr NumericArrayResize(int32 typeCode, int32 numDims, UHandle *dataHP, int32 totalNewSize);

Purpose

NumericArrayResize resizes a data handle referring to a numeric array. This routine also accounts for alignment issues. It does not set the array dimension field. If *dataHP is NULL, LabVIEW allocates a new array handle in *dataHP.

Parameters

Name

Type

Description

 

 

 

 

 

 

typeCode

int32

Data type for the array you want to resize. The header file

 

 

extcode.h defines the following constants for this argument:

 

 

iB Array of signed 8-bit integers

 

 

iW Array of signed 16-bit integers

 

 

iL Array of signed 32-bit integers

 

 

uB Array of unsigned 8-bit integers

 

 

uW Array of unsigned 16-bit integers

 

 

uL Array of unsigned 32-bit integers

 

 

fS Array of single-precision (32-bit) numbers

 

 

fD Array of double-precision (64-bit) numbers

 

 

fX Array of extendedprecision numbers

 

 

cS Array of single-precision complex numbers

 

 

cD Array of double-precision complex numbers

 

 

cX Array of extended-precision complex numbers

 

 

 

numDims

int32

Number of dimensions in the data structure to which the handle

 

 

refers. Thus, if the handle refers to a two-dimensional array,

 

 

pass a value of 2.

 

 

 

Using External Code in LabVIEW

4-12

www.ni.com

 

 

Chapter 4 Programming Issues for CINs

 

 

 

Name

Type

Description

 

 

 

 

 

 

*dataHP

UHandle

Pointer to the handle you want to resize. If this is a pointer

 

 

to NULL, LabVIEW allocates and sizes a new handle

 

 

appropriately and returns the handle in *dataHP.

 

 

 

totalNewSize

int32

New number of elements to which the handle should refer. For

 

 

a unidimensional array of five values, pass a value of 5. For a

 

 

two-dimensional array of two rows by three columns, pass a

 

 

value of 6.

 

 

 

Return Values

MgErr, which can contain the errors in the following list. Refer to the Manager Overview section later in this chapter for more information about MgErr.

noErr

No error.

mFullErr

Not enough memory to perform operation.

mZoneErr

Handle is not in specified zone.

© National Instruments Corporation

4-13

Using External Code in LabVIEW

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