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

Chapter 6 Function Descriptions

ToLower

uChar ToLower(c);

Purpose

Returns the lowercase value of c if c is an uppercase alphabetic character. Otherwise, this function returns c unmodified. In SPARCstation, this function also works for international characters (Ä to ä, and so on).

Parameters

Name

Type

Description

 

 

 

 

 

 

c

int32

Character you want to analyze.

 

 

 

Return Value

The lowercase value of c.

Using External Code in LabVIEW

6-174

www.ni.com

Chapter 6 Function Descriptions

ToUpper

uChar ToUpper(c);

Purpose

Returns the uppercase value of c if c is a lowercase alphabetic character. Otherwise, this function returns c unmodified. In SPARCstation, this function also works for international characters (ä to Ä, and so on).

Parameters

Name

Type

Description

 

 

 

 

 

 

c

int32

Character you want to analyze.

 

 

 

Return Value

The uppercase value of c.

© National Instruments Corporation

6-175

Using External Code in LabVIEW

Chapter 6 Function Descriptions

Unused

Macro

void Unused(x)

Purpose

Indicates that a function parameter or local variable is not used by that function. This is useful for suppressing compiler warnings for many compilers. This macro does not use a semicolon.

Parameters

Name

Type

Description

 

 

 

 

 

 

x

Unused parameter or local variable.

 

 

 

Using External Code in LabVIEW

6-176

www.ni.com

Chapter 6 Function Descriptions

Word

Macro

int16 Word(hi, lo);

Purpose

Creates an int16 from two int8 parameters.

Parameters

Name

Type

Description

 

 

 

 

 

 

hi

int8

High int8 for the resulting int16.

 

 

 

lo

int8

Low int8 for the resulting int16.

 

 

 

Return Value

The resulting int16.

© National Instruments Corporation

6-177

Using External Code in LabVIEW

A

Common Questions

What languages can I use to write DLLs?

Any language can be used to write DLLs as long as the DLL can be called using one of the calling conventions that LabVIEW supports (stdcall or C).

Why is it no longer possible to build external subroutines in

LabVIEW?

External subroutines provided a solution for users who wanted to share code among multiple CINs. At the time that LabVIEW first provided for external subroutines, shared libraries (DLLs) were not yet commonplace. Since shared libraries are now widely used, and since they provide all the functionality that external subroutines did, National Instruments decided to drop support for the creation of external subroutines. Users who want to share code among multiple CINs should use shared libraries.

Why does the “Function Name” ring contain an empty list of functions for certain DLLs?

On Windows platforms, the most likely reason is that the DLL is 16-bit. LabVIEW cannot call 16-bit DLLs. It is also possible, though unlikely, that the DLL has no exported functions. The UNIX platforms do not implement this functionality.

Why does the function I wish to call not appear in the “Function

Name” ring of the Call Library Function configuration dialog?

The most likely reason is that the function has not been exported. See the documentation for your compiler for information about how to mark functions for export.

Why does LabVIEW crash when I call a function in my DLL?

The most likely causes are: 1) an error in the calling convention you have specified in the Call Library Function configuration dialog; 2) one of the function parameters being of incorrect type; and 3) an error in the code of the DLL, such as dereferencing a null pointer.

© National Instruments Corporation

A-1

Using External Code in LabVIEW

Chapter A Common Questions

In the Function Prototype section of the Call Library Function configuration dialog, why does the function name have unusual characters appended?

The function name that appears in the function prototype section will have characters such as “@” appended if the function was “decorated” when the DLL was built. This is most common with C++ compilers. This is normal and not a cause for concern. The undecorated name will appear in the Function Name ring of the configuration dialog.

Why do I receive memory.cpp errors when I call a function in my

DLL?

The cause is almost always an error in the code of the DLL, such as writing past the end of the memory allocated for an array. Note that these kinds of crashes may or may not occur at the time the DLL call actually executes on the block diagram.

Is it possible to return a pointer from a call to a function in a DLL?

Strictly speaking, this is not possible, because there are no pointer types in LabVIEW. However, you can specify the return type to be an integer that is the same size as the pointer. LabVIEW will then treat the address as a simple integer.

Is it possible to allocate memory using malloc inside a CIN?

Yes, but the pointer that results from the malloc call should be assigned to a variable that is local to the CIN code, rather than to a variable passed from the LabVIEW diagram. You should use LabVIEW memory manager functions if you wish to create or resize memory associated with a variable passed from the LabVIEW diagram.

Can CINs be written in a language other than C?

This is technically possible if the CIN entry points (i.e. CINRun, CINLoad, etc.) are declared as extern "C". However, National Instruments recommends using a DLL rather than a CIN if you wish to use a language other than C or C++.

What are the advantages of using a CIN rather than a DLL?

The advantages are: 1) the CIN code is integrated into the code of the VI, so there is no extra file to maintain when the VI is distributed; 2) CINs provide certain special entry points (CINLoad, CINSave, etc.).

Using External Code in LabVIEW

A-2

www.ni.com

Chapter A Common Questions

What are the advantages of using a DLL rather than a CIN?

The advantages are: 1) you can change the DLL without changing any of the VIs that link to the DLL (provided you do not modify the function prototypes); 2) Practically all modern development environments provide excellent support for creating DLLs, while LabVIEW supports only a subset of development environments for creating CINs.

Is it possible to call the LabVIEW manager functions from a DLL?

Yes. You need to #include extcode.h in any files that use manager functions, and you must link to labview.lib. You should also set your compiler's structure alignment to 1 byte. Note that some of the manager functions, such as SetCINArraySize, are CIN-specific and may not be called from a DLL.

Is it faster to call a DLL or a CIN, assuming the underlying code is the same?

There is no difference in speed.

One or more of the parameters of the function I wish to call in a DLL are of types that do not exist in LabVIEW. Can I still call this function from LabVIEW?

You can call the function, but you must ensure that each parameter is passed to the function in a way that allows the DLL to correctly interpret the data. Starting in LabVIEW 6.0, the Call Library Function allows you to create a skeleton .c file from its current configuration. By viewing this C file, you can determine whether LabVIEW will pass the data in a manner compatible with the DLL function, and make necessary adjustments.

© National Instruments Corporation

A-3

Using External Code in LabVIEW

B

Technical Support Resources

Web Support

National Instruments Web support is your first stop for help in solving installation, configuration, and application problems and questions. Online problem-solving and diagnostic resources include frequently asked questions, knowledge bases, product-specific troubleshooting wizards, manuals, drivers, software updates, and more. Web support is available through the Technical Support section of www.ni.com

NI Developer Zone

The NI Developer Zone at zone.ni.com is the essential resource for building measurement and automation systems. At the NI Developer Zone, you can easily access the latest example programs, system configurators, tutorials, technical news, as well as a community of developers ready to share their own techniques.

Customer Education

National Instruments provides a number of alternatives to satisfy your training needs, from self-paced tutorials, videos, and interactive CDs to instructor-led hands-on courses at locations around the world. Visit the Customer Education section of www.ni.com for online course schedules, syllabi, training centers, and class registration.

System Integration

If you have time constraints, limited in-house technical resources, or other dilemmas, you may prefer to employ consulting or system integration services. You can rely on the expertise available through our worldwide network of Alliance Program members. To find out more about our Alliance system integration solutions, visit the System Integration section of www.ni.com

© National Instruments Corporation

B-1

Using External Code in LabVIEW

Appendix B Technical Support Resources

Worldwide Support

National Instruments has offices located around the world to help address your support needs. You can access our branch office Web sites from the Worldwide Offices section of www.ni.com. Branch office web sites provide up-to-date contact information, support phone numbers, e-mail addresses, and current events.

If you have searched the technical support resources on our Web site and still cannot find the answers you need, contact your local office or National Instruments corporate. Phone numbers for our worldwide offices are listed at the front of this manual.

Using External Code in LabVIEW

B-2

www.ni.com

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