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

Chapter 2 Shared Libraries (DLLs)

Create Front Panel

Create the front panel of the VI as follows.

1.Place an array control, Array, to contain a scalar array of SGL with four members.

2.Place a numeric SGL indicator, Average Value, to display the result of your averaging calculation.

3.Place a numeric indicator, Error, to display any errors that your VI generates.

Create the Block Diagram

Perform the following steps to complete the block diagram.

1.Connect the icons for following front panel controls to the Call Library Function icon.

a.Connect the Array of data control to the a input.

b.Connect the Array Size control to the size input.

c.Connect a constant, zero, to the avg input.

d.Connect the Average Value indicator to the avg output.

e.Connect the Error indicator to the error output.

2.In the front panel, add dummy values to the array and run the VI to calculate the average of those values.

3.Save your work and close the VI.

If your DLL returns incorrect results or crashes, verify the data types and wiring to see if you wired the wrong type of information. If you require further help, several sections in this chapter present troubleshooting tips and pitfalls to avoid.

Example 2: Call a Hardware Driver API

LabVIEW users frequently want to access an API associated with hardware that they have purchased. With National Instruments hardware, however, you do not need to use the shared library object to gain access; all National Instruments products come with LabVIEW interfaces.

In this example you call a hypothetical interface card for a databus called “X-bus.” The X-bus interface card comes with a software driver for your operating system. The X-bus documentation provides standard information:

A listing of all functions that you can use to access the hardware.

© National Instruments Corporation

2-17

Using External Code in LabVIEW

Chapter 2 Shared Libraries (DLLs)

Description of the shared library file xbus.dll that contains these functions.

Instructions on including a header file xbus.h. Although LabVIEW does not permit you to include such header files, you can open header files and extract information about function prototypes and constants.

A statement about the Standard (__stdcall) calling convention that the X-bus library uses.

One of the functions you want to use with this hypothetical hardware is XBusRead16, which reads a 16-bit integer from a certain address. The documentation describes XBusRead16 as follows:

long XBusRead16(unsigned long offset, short* data);

Puts 16 bits from the register at “offset” into the memory location pointed to by “data.” Returns 1 if successful, or 0 if it fails.

Given this information, you can configure the LabVIEW Call Library

Function appropriately, as follows:

1.Create a new VI called Read Data and place a Call Library Function object in the Block diagram.

2.Right-click the Call Library Function object and select Configure in the shortcut menu.

3.In the Call Library Function dialog box, make the following settings.

a.Select stdcall (WINAPI) in the Calling Conventions control.

b.Type XbusRead16, in the Function Name control.

c.Select Signed 32 bit Integer in the Data Type control for the return type parameter.

d.Add a parameter and name it offset and select Unsigned 32 bit Integer in the Data Type control.

e.Add a parameter and name it data and set its data type to be pointer to a signed 16-bit integer.

4.Inspect the function prototype that appears in the Function Prototype indicator. If this the prototype you see does not match the definition of the function in the API you are calling, you must change your settings in the Call Library Function dialog box.

The following graphic shows what the front panel and block diagram of the final VI that calls xbus.dll might look like.

Using External Code in LabVIEW

2-18

www.ni.com

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