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

Chapter 2 Shared Libraries (DLLs)

If you pass the array data as a LabVIEW Array Handle, you can use LabVIEW CIN functions to resize the array. In order to call LabVIEW CIN functions, your compile must include the correct LabVIEW library file, which is located within the LabVIEW cintools directory.

For CodeWarrior, include labview.export.stub.

For Symantec, include labview.sym.lib.

For Visual C++, include labview.lib.

String Data

The types of your string pointers much match the types of string pointers that your function uses, or errors will occur. Call Library Function offers the following choices:

C String Pointer—Pointer to the string, followed by a NULL character. Most Win32 API functions use this C-style string pointer.

Pascal String Pointer—Pointer to the string, preceded by a length byte.

LabVIEW String Handle—Pointer to a pointer to the string, preceded by four bytes of length information.

LabVIEW String Handle Pointer—A pointer to a handle for a string, preceded by four bytes of length information.

You can think of a string as an array of characters; assembling the characters in order forms a string. LabVIEW stores a string in a special format in which the first four bytes of the array of characters form a signed 32-bit integer that stores how many characters appear in the string. Thus, a string with n characters will require n + 4 bytes to store in memory. For example, in the following graphic the string text contains four characters. When LabVIEW stores the string, the first four bytes contain the value 4 as a signed 32-bit number, and each of the following four bytes contains a character of the string. The advantage of this type of string storage is that NULL characters are allowed in the string. Strings are virtually unlimited in length (up to 231 characters). This method of string storage is illustrated in the following figure. If you pass a LabVIEW String Handle from Call Library Function to the DLL, then you can use the LabVIEW CIN functions like DSSetHandleSize to resize the LabVIEW String Handle.

 

 

 

 

 

 

 

 

 

 

 

\00

\00

\00

\04

t

e

x

t

 

 

string length

 

string data

 

 

 

 

 

 

 

 

 

 

 

 

Figure 2-9. The LabVIEW String Format

© National Instruments Corporation

2-31

Using External Code in LabVIEW

Chapter 2 Shared Libraries (DLLs)

Remember, you must add labview.lib to a Visual C++ project, labview.export.stub to a CodeWarrior project, and labview.sym.lib to a Symantec project.

The Pascal string format is nearly identical to the LabVIEW string format, but instead of storing the length of the string as a signed 32-bit integer, it is stored as an unsigned 8-bit integer. This limits the length of a Pascal style string to 255 characters. A graphical representation of a Pascal string appears in the following figure. A Pascal string that is n characters long will require n + 1 bytes of memory to store.

\04 t

e

x

t

string data

string length

Figure 2-10. The Pascal String Format

C strings are probably the type of strings you will deal with most commonly. The similarities between the C-style string and normal numeric arrays in C becomes much more clear when one observes that C strings are declared as char *, where char is typically an unsigned byte. Unlike LabVIEW and Pascal strings, C strings do not contain any information that directly gives the length of the string. Instead, C strings use a special character, called the NULL character, to indicate the end of the string. NULL is defined to have a value of zero in the ASCII character set. Notice that NULL is the number zero and not the character “0”. Thus, in C, a string containing n characters requires n + 1 bytes of memory to store: n bytes for the characters in the string, and one additional byte for the NULL termination character. The advantage of C-style strings is that they are limited in size only by available memory. However, if you are acquiring data from an instrument that returns numeric data as a binary string, as is common with serial or GPIB instruments, values of zero in the string are possible. For binary data where NULLs may be present, consider an array of unsigned 8-bit integers. If you treat the string as a C-style string, your program will incorrectly assume that the end of the string has been reached, when in fact your instrument is returning a numeric value of zero. An illustration of how a C-style string is stored in memory appears in the following figure.

Using External Code in LabVIEW

2-32

www.ni.com

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