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

Chapter 2 Shared Libraries (DLLs)

Write a CIN that can accept arbitrary data structures. Refer to Chapter 3, CINs, for more information about writing CINs.

Building a Shared Library (DLL)

This section uses a simple shared library example to describe the three basic tasks for building external code libraries to call from LabVIEW:

Task 1: Build the Function Prototype in LabVIEW

Task 2: Complete the .c File

Task 3: Build a Library Project in an External IDE

In the Example 1: Call a Shared Library that You Built section, you will call the shared library that you build here.

Task 1: Build the Function Prototype in LabVIEW

To build a function prototype for your shared library, you must build a prototype in LabVIEW and then fill in all the details of your code. When you allow LabVIEW to generate this C source code, you help ensure that the basic syntax of the code in your shared library will be valid.

Perform the following steps to build your prototype source file, myshared.c.

1.Create a VI called Array Average in LabVIEW, and access the block diagram. Select Functions»Advanced»Call Library Function and place this object on the block diagram.

2.Right-click the Call Library Function icon and select Configure in the shortcut menu to invoke the Call Library Function dialog box. Leave the Library Name or Path control empty.

3.Enter the following general specifications.

a.Type avg_num in the Function Name field.

b.Select C in the Calling Conventions control.

4.Define the return value:

a.In the Parameter control change the default name, return type, to a more descriptive name, error.

b.In the Type control select Numeric.

c.In the Data Type control select Signed 32-bit Integer.

Using External Code in LabVIEW

2-6

www.ni.com

Chapter 2 Shared Libraries (DLLs)

5.Define the a parameter:

a.Click the Add Parameter After button.

b.In the Parameter control replace the default name, arg1, with the precise name, a.

c.In the Type control select Array.

d.In the Data Type control select 4-byte Single.

e.In the Array Format control select Array Data Pointer.

Note The Array and String Options section describes the available settings for arrays and strings in the Call Library Function icon.

6.Define size:

a.Click the Add Parameter After button.

b.In the Parameter control replace the default name, arg2, with the precise name, size.

c.In the Type control select Numeric.

d.In the Data Type control select Signed 32-bit Integer.

e.In the Pass control select Value.

7.Define avg:

a.Click the Add Parameter After button.

b.In the Parameter control replace the default name, arg3, with the precise name, avg.

c.In the Type control select Numeric type.

d.In the Data Type control select 4-byte Single.

e.In the Pass control select Pointer to Value.

8.Check that the Function Prototype indicator displays the return value and three parameters in the correct order, as follows:

long avg_num(float *a, long size, float *avg)

Note The syntax you see in the Function Prototype indicator is technically correct. However, the .c file that LabVIEW generates in the next section will be more precise because the first parameter will appear as float a[].

9.Click OK to save your settings and close the dialog box.

10.Observe how the Call Library Function icon updates to reflect your settings.

© National Instruments Corporation

2-7

Using External Code in LabVIEW

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