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

Contents

About This Manual

Conventions ...................................................................................................................

xiii

Related Documentation..................................................................................................

xiv

Chapter 1

Introduction

Calling Code in Various Platforms ................................................................................

1-1

Characteristics of the Two Calling Approaches ............................................................

1-2

Details of Call Library Function......................................................................

1-3

Details of a CIN...............................................................................................

1-3

Chapter 2

Shared Libraries (DLLs)

Calling Shared Libraries ................................................................................................

2-1

Calling Conventions (Windows) .....................................................................

2-3

Parameters .......................................................................................................

2-3

Calling Functions That Expect Other Data Types...........................................

2-5

Building a Shared Library (DLL) ..................................................................................

2-6

Task 1: Build the Function Prototype in LabVIEW ........................................

2-6

Task 2: Complete the .c File............................................................................

2-8

Task 3: Build a Library Project in an External IDE ........................................

2-10

Calling External APIs ....................................................................................................

2-14

Common Pitfalls with the Call Library Function ............................................

2-14

Example 1: Call a Shared Library that You Built ...........................................

2-16

Example 2: Call a Hardware Driver API.........................................................

2-17

Example 3: Call the Win32 API ......................................................................

2-19

Additional Examples of LabVIEW Calls to DLLs ........................................................

2-25

Debugging DLLs and Calls to DLLs .............................................................................

2-26

Troubleshooting the Call Library Function .....................................................

2-26

Troubleshooting your DLL..............................................................................

2-26

Troubleshooting Checklist...............................................................................

2-27

Module Definition Files.................................................................................................

2-29

Array and String Options ...............................................................................................

2-30

Arrays of Numeric Data ..................................................................................

2-30

String Data.......................................................................................................

2-31

Array and String Tip........................................................................................

2-33

© National Instruments Corporation

v

Using External Code in LabVIEW

Contents

Chapter 3

CINs

Supported Languages ....................................................................................................

3-1

Macintosh........................................................................................................

3-1

Microsoft Windows.........................................................................................

3-1

Solaris, Linux, and HP-UX .............................................................................

3-2

Resolving Multithreading Issues ...................................................................................

3-2

Making LabVIEW Recognize a CIN as Thread Safe .....................................

3-2

Using C Code that is Thread Safe ...................................................................

3-3

Creating a CIN...............................................................................................................

3-3

Step 1. Set Up Input and Output Terminals for a CIN....................................

3-4

Step 2. Wire the Inputs and Outputs to the CIN .............................................

3-6

Step 3. Create a .c File ....................................................................................

3-6

Step 4. Compile the CIN Source Code ...........................................................

3-8

Step 5. Load the CIN Object Code .................................................................

3-16

LabVIEW Manager Routines ........................................................................................

3-16

Pointers as Parameters ....................................................................................

3-17

Debugging External Code .............................................................................................

3-18

DbgPrintf.........................................................................................................

3-19

Windows .........................................................................................................

3-19

UNIX...............................................................................................................

3-21

Chapter 4

Programming Issues for CINs

Passing Parameters ........................................................................................................

4-1

Parameters in the CIN .c File ..........................................................................

4-1

Passing Fixed-Size Data to CINs ....................................................................

4-2

Return Value for CIN Routines ......................................................................

4-3

Examples with Scalars ....................................................................................

4-4

Creating a CIN That Multiplies Two Numbers ..............................................

4-4

Passing Variably Sized Data to CINs ............................................................................

4-7

Resizing Arrays and Strings............................................................................

4-9

SetCINArraySize ..............................................................................

4-11

NumericArrayResize ........................................................................

4-12

Examples with Variably Sized Data ...............................................................

4-14

Manager Overview ........................................................................................................

4-21

Basic Data Types ............................................................................................

4-23

Memory Manager............................................................................................

4-27

File Manager..................................................................................................................

4-32

Support Manager.............................................................................................

4-36

Using External Code in LabVIEW

vi

www.ni.com

 

Contents

Chapter 5

 

Advanced Applications

 

CIN Routines .................................................................................................................

5-1

Data Spaces and Code Resources....................................................................

5-1

One Reference to the CIN in a Single VI ........................................................

5-3

Multiple References to the Same CIN in a Single VI .....................................

5-5

Multiple References to the Same CIN in Different VIs ..................................

5-6

Code Globals and CIN Data Space Globals ....................................................

5-8

Chapter 6

 

Function Descriptions

 

Memory Manager Functions..........................................................................................

6-1

Support Manager Functions...........................................................................................

6-5

Mathematical Operations.................................................................................

6-8

Abs .................................................................................................................................

6-9

ASCIITime.....................................................................................................................

6-10

AZCheckHandle/DSCheckHandle ................................................................................

6-11

AZCheckPtr/DSCheckPtr ..............................................................................................

6-12

AZDisposeHandle/DSDisposeHandle ...........................................................................

6-13

AZDisposePtr/DSDisposePtr.........................................................................................

6-14

AZGetHandleSize/DSGetHandleSize ...........................................................................

6-15

AZHandAndHand/DSHandAndHand ...........................................................................

6-16

AZHandToHand/DSHandToHand ................................................................................

6-17

AZHeapCheck/DSHeapCheck.......................................................................................

6-18

AZHLock .......................................................................................................................

6-19

AZHNoPurge .................................................................................................................

6-20

AZHPurge ......................................................................................................................

6-21

AZHUnlock ...................................................................................................................

6-22

AZMaxMem/DSMaxMem ............................................................................................

6-23

AZMemStats/DSMemStats ...........................................................................................

6-24

AZNewHandle/DSNewHandle......................................................................................

6-25

AZNewHClr/DSNewHClr.............................................................................................

6-26

AZNewPClr/DSNewPClr ..............................................................................................

6-27

AZNewPtr/DSNewPtr ...................................................................................................

6-28

AZPtrAndHand/DSPtrAndHand ...................................................................................

6-29

AZPtrToHand/DSPtrToHand ........................................................................................

6-30

AZPtrToXHand/DSPtrToXHand...................................................................................

6-31

AZRecoverHandle/DSRecoverHandle ..........................................................................

6-32

AZSetHandleSize/DSSetHandleSize.............................................................................

6-33

AZSetHSzClr/DSSetHSzClr..........................................................................................

6-34

BinSearch.......................................................................................................................

6-35

BlockCmp ......................................................................................................................

6-36

© National Instruments Corporation

vii

Using External Code in LabVIEW

Contents

Cat4Chrs ........................................................................................................................

6-37

ClearMem ......................................................................................................................

6-38

CPStrBuf........................................................................................................................

6-39

CPStrCmp......................................................................................................................

6-40

CPStrIndex ....................................................................................................................

6-41

CPStrInsert ....................................................................................................................

6-42

CPStrLen .......................................................................................................................

6-43

CPStrRemove ................................................................................................................

6-44

CPStrReplace.................................................................................................................

6-45

CPStrSize.......................................................................................................................

6-46

CToPStr .........................................................................................................................

6-47

DateCString ...................................................................................................................

6-48

DateToSecs....................................................................................................................

6-49

FAddPath .......................................................................................................................

6-50

FAppendName...............................................................................................................

6-51

FAppPath .......................................................................................................................

6-52

FArrToPath....................................................................................................................

6-53

FCopy ............................................................................................................................

6-54

FCreate ..........................................................................................................................

6-55

FCreateAlways ..............................................................................................................

6-57

FDepth ...........................................................................................................................

6-59

FDirName ......................................................................................................................

6-60

FDisposePath .................................................................................................................

6-61

FDisposeRefNum ..........................................................................................................

6-62

FEmptyPath ...................................................................................................................

6-63

FExists ...........................................................................................................................

6-64

FFlattenPath...................................................................................................................

6-65

FFlush ............................................................................................................................

6-66

FGetAccessRights .........................................................................................................

6-67

FGetDefGroup ...............................................................................................................

6-68

FGetEOF........................................................................................................................

6-69

FGetInfo ........................................................................................................................

6-70

FGetPathType................................................................................................................

6-72

FGetVolInfo ..................................................................................................................

6-73

FileNameCmp................................................................................................................

6-74

FileNameIndCmp ..........................................................................................................

6-75

FileNameNCmp.............................................................................................................

6-76

FIsAPath ........................................................................................................................

6-77

FIsAPathOfType............................................................................................................

6-78

FIsAPathOrNotAPath....................................................................................................

6-79

FIsARefNum .................................................................................................................

6-80

FIsEmptyPath ................................................................................................................

6-81

FListDir .........................................................................................................................

6-82

FLockOrUnlockRange ..................................................................................................

6-84

Using External Code in LabVIEW

viii

www.ni.com

 

Contents

FMakePath .....................................................................................................................

6-86

FMClose.........................................................................................................................

6-87

FMOpen .........................................................................................................................

6-88

FMove ............................................................................................................................

6-91

FMRead .........................................................................................................................

6-92

FMSeek ..........................................................................................................................

6-93

FMTell ...........................................................................................................................

6-94

FMWrite.........................................................................................................................

6-95

FName............................................................................................................................

6-96

FNamePtr .......................................................................................................................

6-97

FNewDir ........................................................................................................................

6-98

FNewRefNum ................................................................................................................

6-99

FNotAPath .....................................................................................................................

6-100

FPathCmp ......................................................................................................................

6-101

FPathCpy .......................................................................................................................

6-102

FPathToArr ....................................................................................................................

6-103

FPathToAZString...........................................................................................................

6-104

FPathToDSString...........................................................................................................

6-105

FPathToPath...................................................................................................................

6-106

FRefNumToFD ..............................................................................................................

6-107

FRefNumToPath ............................................................................................................

6-108

FRelPath.........................................................................................................................

6-109

FRemove ........................................................................................................................

6-110

FSetAccessRights ..........................................................................................................

6-111

FSetEOF.........................................................................................................................

6-112

FSetInfo .........................................................................................................................

6-113

FSetPathType.................................................................................................................

6-115

FStrFitsPat .....................................................................................................................

6-116

FStringToPath ................................................................................................................

6-117

FTextToPath ..................................................................................................................

6-118

FUnFlattenPath ..............................................................................................................

6-119

FVolName......................................................................................................................

6-120

GetALong ......................................................................................................................

6-121

HexChar .........................................................................................................................

6-122

Hi16 ...............................................................................................................................

6-123

HiByte ............................................................................................................................

6-124

HiNibble.........................................................................................................................

6-125

IsAlpha...........................................................................................................................

6-126

IsDigit ............................................................................................................................

6-127

IsLower ..........................................................................................................................

6-128

IsUpper...........................................................................................................................

6-129

Lo16 ...............................................................................................................................

6-130

LoByte ...........................................................................................................................

6-131

Long ...............................................................................................................................

6-132

© National Instruments Corporation

ix

Using External Code in LabVIEW

Contents

LoNibble........................................................................................................................

6-133

LStrBuf ..........................................................................................................................

6-134

LStrCmp ........................................................................................................................

6-135

LStrLen..........................................................................................................................

6-136

LToPStr .........................................................................................................................

6-137

Max................................................................................................................................

6-138

MilliSecs........................................................................................................................

6-139

Min ................................................................................................................................

6-140

MoveBlock ....................................................................................................................

6-141

NumericArrayResize .....................................................................................................

6-142

Offset .............................................................................................................................

6-143

Pin..................................................................................................................................

6-144

PPStrCaseCmp ..............................................................................................................

6-145

PPStrCmp ......................................................................................................................

6-146

PStrBuf ..........................................................................................................................

6-150

PStrCaseCmp.................................................................................................................

6-151

PStrCat...........................................................................................................................

6-152

PStrCmp ........................................................................................................................

6-153

PStrCpy..........................................................................................................................

6-154

PStrLen ..........................................................................................................................

6-155

PStrNCpy.......................................................................................................................

6-156

PToCStr .........................................................................................................................

6-157

PToLStr .........................................................................................................................

6-158

QSort..............................................................................................................................

6-159

RandomGen ...................................................................................................................

6-160

SecsToDate....................................................................................................................

6-161

SetALong.......................................................................................................................

6-162

SetCINArraySize ...........................................................................................................

6-163

StrCat .............................................................................................................................

6-164

StrCmp...........................................................................................................................

6-165

StrCpy............................................................................................................................

6-166

StrLen ............................................................................................................................

6-167

StrNCaseCmp ................................................................................................................

6-168

StrNCmp........................................................................................................................

6-169

StrNCpy .........................................................................................................................

6-170

SwapBlock.....................................................................................................................

6-171

TimeCString ..................................................................................................................

6-172

TimeInSecs ....................................................................................................................

6-173

ToLower ........................................................................................................................

6-174

ToUpper.........................................................................................................................

6-175

Unused ...........................................................................................................................

6-176

Word ..............................................................................................................................

6-177

Using External Code in LabVIEW

x

www.ni.com

Contents

Appendix A

Common Questions

Appendix B

Technical Support Resources

Glossary

© National Instruments Corporation

xi

Using External Code in LabVIEW

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