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

Chapter 4 Programming Issues for CINs

if(err = DSHandToHand((UHandle *) &newStringh))

goto out;

newNumElements = size+1;

if(err =

SetCINArraySize((UHandle)clusterTableh,

ParamNumber, newNumElements)) {

DSDisposeHandle(newStringh);

goto out;

}

(*clusterTableh)–>dimSize = size+1;

newElementp = &((*clusterTableh) –>arg1[size]);

newElementp–>number = elementp–>number;

newElementp–>string = newStringh;

*positionp = size;

out:

return err;

}

In this example, CINRun is the only routine performing substantial operations. CINRun first searches through the table to see if the element is present. CINRun then compares string components using the LabVIEW routine LStrCmp, which is described in Chapter 6, Function Descriptions. If CINRun finds the element, the routine returns the position of the element in the array.

4.If the routine does not find the element, add a new element to the array. Use the memory manager routine DSHandToHand to create a new handle containing the same string as the one in the cluster element you passed to the CIN. CINRun increases the size of the array using SetCINArraySize and fills the last position with a copy of the element you passed to the CIN.

If the SetCINArraySize call fails, the CIN returns the error code returned by the manager. If the CIN is unable to resize the array, LabVIEW disposes of the duplicate string handle.

Manager Overview

LabVIEW has a large number of external functions that you can use to perform simple and complex operations. These functions, organized into libraries called managers, range from low-level byte manipulation to routines for sorting data and managing memory. All manager routines described in this chapter are platform-independent. If you use these

© National Instruments Corporation

4-21

Using External Code in LabVIEW

Chapter 4 Programming Issues for CINs

routines, you can create external code that works on all platforms that LabVIEW supports.

To achieve platform independence, data types should not depend on the peculiarities of various compilers. For example, the C language does not define the size of an integer. Without an explicit definition of the size of each data type, it is almost impossible to create code that works identically across multiple compilers.

LabVIEW managers use data types that explicitly indicate their size. For example, if a routine requires a 4-byte integer as a parameter, you

define the parameter as an int32. The managers define data types in terms of the fundamental data types for each compiler. Thus, on one compiler, the managers might define an int32 as an int, while on another compiler, the managers might define an int32 as a long int. When your writer external code, use the manager data types instead of the host computer data types, so your code is more portable and has fewer errors.

Most applications need routines for allocating and deallocating memory on request. You can use the memory manager to dynamically allocate, manipulate, and release memory. The LabVIEW memory manager supports dynamic allocation of both non-relocatable and relocatable blocks, using pointers and handles. Refer to the Memory Manager section later in this chapter for more information.

Applications that manipulate files can use the functions in the file manager. This set of routines supports basic file operations such as creating, opening, and closing files, writing data to files, and reading data from files. In addition, you can use file manager routines to create directories, determine characteristics of files and directories, and copy files. File manager routines use a LabVIEW data type for file pathnames (Paths) that indicates a file or directory path independent of the platform. You can translate a Path to and from a host platform’s conventional format for describing a file pathname. Refer to the File Manager section later in this chapter for more information.

The support manager contains a collection of generally useful functions, such as functions for bit or byte manipulation of data, string manipulation, mathematical operations, sorting, searching, and determining the current time and date. Refer to the Support Manager section later in this chapter for more information.

Using External Code in LabVIEW

4-22

www.ni.com

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