Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Labview Code Interface Reference Manual.pdf
Скачиваний:
35
Добавлен:
29.05.2015
Размер:
1.13 Mб
Скачать

About This Manual

Note: This icon to the left of bold italicized text denotes a note, which alerts you to important information.

Abbreviations, acronyms, metric prefixes, mnemonics, symbols, and terms are listed in the Glossary.

Related Documentation

The following documents contain information that you may find helpful as you read this manual:

Your LabVIEW analysis VI reference manual

LabVIEW Instrument I/O VI Reference Manual

Your LabVIEW Tutorial

Your LabVIEW User Manual

Sun users may also find the following document useful:

SPARCompiler C 3.0 Answer Book CD-ROM, Sun Microsystems, Inc., U.S.A., 1993

Windows users may also find the following documents useful:

Microsoft Windows documentation set, Microsoft Corporation, Redmond, WA, 1992-1995

Microsoft Windows Programmer’s Reference, Microsoft Corporation, Redmond, WA, 1992-1995

Win32 Programmer’s Reference, Microsoft Corporation, Redmond, WA, 1992-1995

Watcom C/C++ User’s Guide CD-ROM, Watcom Publications Limited, Waterloo, Ontario, Canada, 1995; Help file: “The Watcom C/C++ Compilers”

Customer Communication

National Instruments wants to receive your comments on our products and manuals. We are interested in the applications you develop with our products, and we want to help if you have problems with them. To make it easy for you to contact us, this manual contains comment and configuration forms for you to complete. These forms are in Appendix B, Customer Communication, at the end of this manual.

© National Instruments Corporation

iii

LabVIEW Code Interface Reference Manual

About This Manual

LabVIEW Code Interface Reference Manual

iv

© National Instruments Corporation

Table

of

Contents

About This Manual

Organization of This Manual ........................................................................................

i

Conventions Used in This Manual ................................................................................

ii

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

iii

Customer Communication ............................................................................................

iii

Chapter 1

CIN Overview

Introduction ...................................................................................................................

 

 

1-1

Classes of External Code ................................................................................

 

 

1-2

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

 

 

1-3

 

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

 

 

1-3

 

Microsoft Windows 3.1

....................................................................

 

1-4

 

Microsoft Windows 95 and Windows NT .......................................

1-4

 

Solaris ...............................................................................................

 

 

1-5

 

HP-UX ..............................................................................................

 

 

1-5

Steps for Creating a CIN ...............................................................................................

 

 

1-5

1.

Place the CIN on a Block Diagram .............................................................

 

1-6

2.

Add Input and Output Terminals to the CIN

..............................................

1-6

 

Input-Output Terminals

....................................................................

 

1-7

 

Output-Only Terminals

....................................................................

 

1-8

3.

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

 

1-9

4.

Create .c File ...............................................................................................

 

 

1-9

 

Special Macintosh Considerations ...................................................

 

1-12

5.

Compile the CIN Source Code ...................................................................

 

1-14

 

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

 

 

1-14

 

Microsoft Windows 3.x

....................................................................

 

1-29

 

Microsoft Windows 95 and Windows NT .......................................

1-32

 

Solaris 1.x .........................................................................................

 

 

1-34

 

Solaris 2.x .........................................................................................

 

 

1-34

 

HP-UX ..............................................................................................

 

 

1-34

 

Unbundled Sun ANSI C Compiler and

 

 

HP-UX C/ANSI C Compiler ..........................................................

 

1-34

6.

Load the CIN Object Code .........................................................................

 

 

1-36

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

 

 

1-36

© National Instruments Corporation

v

LabVIEW Code Interface Reference Manual

Table of Contents

Online Reference ............................................................................................

1-37

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

1-37

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

1-39

Debugging CINs Under Windows 95 and Windows NT ...............................

1-40

Debugging CINs Under Sun or Solaris ..........................................................

1-41

Debugging CINs Under HP-UX ....................................................................

1-41

Chapter 2

CIN Parameter Passing

Introduction ..................................................................................................................

 

2-1

CIN .c File ....................................................................................................................

 

2-1

How LabVIEW Passes Fixed Sized Data to CINs .......................................................

2-2

Scalar Numerics .............................................................................................

2-2

Scalar Booleans ..............................................................................................

2-2

Refnums .........................................................................................................

 

2-3

Clusters of Scalars ..........................................................................................

2-3

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

2-3

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

2-4

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

2-4

1.

Place the CIN on the Block Diagram ..........................................

2-4

2.

Add Two Input and Output Terminals to the CIN .......................

2-4

3.

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

2-4

4.

Create the CIN Source Code ........................................................

2-4

5.

Compile the CIN Source Code ....................................................

2-6

6.

Load the CIN Object Code ..........................................................

2-8

Comparing Two Numbers, Producing a Boolean Scalar ...............................

2-9

How LabVIEW Passes Variably Sized Data to CINs ..................................................

2-10

Alignment Considerations ..............................................................................

2-10

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

2-11

Paths (Path) ....................................................................................................

2-12

Clusters Containing Variably Sized Data ......................................................

2-12

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

2-12

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

2-13

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

2-14

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

2-16

Concatenating Two Strings ............................................................................

2-16

Computing the Cross Product of Two Two-Dimensional Arrays ..................

2-18

Working with Clusters ...................................................................................

2-22

Chapter 3

CIN Advanced Topics

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

3-1

LabVIEW Code Interface Reference Manual

vi

© National Instruments Corporation

 

Table of Contents

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

3-1

CIN Routines: The Basic Case ......................................................................

3-3

Loading a VI ....................................................................................

3-3

Unloading a VI ................................................................................

3-4

Loading a New Resource into the CIN ............................................

3-4

Compiling a VI ................................................................................

3-4

Running a VI ...................................................................................

3-5

Saving a VI ......................................................................................

3-5

Aborting a VI ...................................................................................

3-5

Multiple References to the Same CIN ...........................................................

3-6

Reentrancy .....................................................................................................

3-7

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

3-8

Examples .........................................................................................

3-9

Calling a Windows 95 or Windows NT Dynamic Link Library ..................................

3-13

Calling a Windows 3.1 Dynamic Link Library ............................................................

3-13

Calling a 16-Bit DLL .....................................................................................

3-14

1. Load the DLL ..............................................................................

3-14

2. Get the address of the desired function .......................................

3-15

3. Describe the function ...................................................................

3-15

4. Call the function ..........................................................................

3-16

Example: A CIN that Displays a Dialog Box ................................................

3-16

The DLL ..........................................................................................

3-17

The Block Diagram .........................................................................

3-19

The CIN Code ..................................................................................

3-19

Compiling the CIN ..........................................................................

3-22

Optimization ....................................................................................

3-23

Chapter 4

 

External Subroutines

 

Introduction ..................................................................................................................

4-1

Creating Shared External Subroutines .........................................................................

4-2

External Subroutine .......................................................................................

4-3

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

4-3

Microsoft Windows 3.1, Windows 95, and

 

Windows NT ..................................................................................

4-3

Solaris 1.x, Solaris 2.x, and HP-UX ................................................

4-4

Calling Code .................................................................................................................

4-4

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

4-5

Microsoft Windows 3.1, Windows 95, and Windows NT ..............

4-6

Solaris 1.x, Solaris 2.x, and HP-UX ................................................

4-6

Simple Example ...........................................................................................................

4-7

External Subroutine Example ........................................................................

4-7

Compiling the External Subroutine ...............................................................

4-8

© National Instruments Corporation

vii

LabVIEW Code Interface Reference Manual

Table of Contents

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

4-8

Microsoft Windows 3.1 ...................................................................

4-9

Microsoft Windows 95 and Windows NT .......................................

4-9

Solaris 1.x, Solaris 2.x, and HP-UX ................................................

4-10

Calling Code ...................................................................................................

4-10

Compiling the Calling Code ...........................................................................

4-12

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

4-12

Microsoft Windows 3.1 ...................................................................

4-13

Microsoft Windows 95 and Windows NT .......................................

4-14

Solaris 1.x, Solaris 2.x, and HP-UX ................................................

4-14

Chapter 5

Manager Overview

Introduction ..................................................................................................................

5-1

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

5-2

Scalar Data Types ..........................................................................................

5-2

Booleans ..........................................................................................

5-2

Numerics ..........................................................................................

5-3

char Data Type ...............................................................................................

5-4

Dynamic Data Types ......................................................................................

5-4

Arrays ..............................................................................................

5-4

Strings ..............................................................................................

5-5

C-Style Strings (CStr) ......................................................................

5-5

Pascal-Style Strings (PStr) ...............................................................

5-5

LabVIEW Strings (LStr) ..................................................................

5-5

Concatenated Pascal String (CPStr) ................................................

5-6

Paths (Path) ......................................................................................

5-6

Memory-Related Types ..................................................................................

5-6

Constants ........................................................................................................

5-6

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

5-7

Memory Allocation ........................................................................................

5-7

Static Memory Allocation ................................................................

5-7

Dynamic Memory Allocation: Pointers and Handles ......................

5-8

Memory Zones ...............................................................................................

5-9

Using Pointers and Handles ...........................................................................

5-9

Simple Example ...............................................................................

5-10

Reference to the Memory Manager ................................................................

5-12

Memory Manager Data Structures ...................................................

5-12

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

5-12

Introduction ....................................................................................................

5-13

Identifying Files and Directories ....................................................................

5-13

Path Specifications .........................................................................................

5-14

Conventional Path Specifications ....................................................

5-14

LabVIEW Code Interface Reference Manual

viii

© National Instruments Corporation

 

Table of Contents

Empty Path Specifications ...............................................................

5-15

LabVIEW Path Specification ..........................................................

5-16

File Descriptors ..............................................................................................

5-16

File Refnums ..................................................................................................

5-17

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

5-17

Chapter 6

 

Memory Manager Functions

 

Allocating and Releasing Handles .................................................................

6-1

AZDisposeHandle

 

DSDisposeHandle ..........................................................................

6-1

AZEmptyHandle

 

DSEmptyHandle ............................................................................

6-1

AZGetHandleSize

 

DSGetHandleSize ..........................................................................

6-2

AZNewHandle

 

DSNewHandle ...............................................................................

6-2

AZNewHClr

 

DSNewHClr ...................................................................................

6-2

AZReallocHandle

 

DSReallocHandle ...........................................................................

6-3

AZRecoverHandle

 

DSRecoverHandle .........................................................................

6-3

AZSetHandleSize

 

DSSetHandleSize ...........................................................................

6-4

AZSetHSzClr

 

DSSetHSzClr .................................................................................

6-5

Allocating and Releasing Pointers .................................................................

6-5

AZDisposePtr

 

DSDisposePtr .................................................................................

6-5

AZNewPClr

 

DSNewPClr ...................................................................................

6-6

AZNewPtr

 

DSNewPtr ......................................................................................

6-6

Manipulating Properties of Handles ..............................................................

6-6

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

6-6

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

6-7

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

6-7

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

6-7

Memory Utilities ............................................................................................

6-8

AZHandAndHand

 

DSHandAndHand ..........................................................................

6-8

AZHandToHand

 

© National Instruments Corporation

ix

LabVIEW Code Interface Reference Manual

Table of Contents

DSHandToHand .............................................................................

6-8

AZPtrAndHand

 

DSPtrAndHand ..............................................................................

6-9

AZPtrToHand

 

DSPtrToHand .................................................................................

6-10

AZPtrToXHand

 

DSPtrToXHand ..............................................................................

6-10

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

6-11

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

6-11

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

6-11

Handle and Pointer Verification .....................................................................

6-12

AZCheckHandle

 

DSCheckHandle .............................................................................

6-12

AZCheckPtr

 

DSCheckPtr ....................................................................................

6-12

Memory Zone Utilities ...................................................................................

6-13

AZHeapCheck

 

DSHeapCheck ................................................................................

6-13

AZMaxMem

 

DSMaxMem ...................................................................................

6-13

AZMemStats

 

DSMemStats ..................................................................................

6-14

Chapter 7

File Manager Functions

File Manager Data Structures .......................................................................................

7-1

File/Directory Information Record ................................................................

7-1

File Type Record ............................................................................................

7-2

Path Data Type ...............................................................................................

7-3

Permissions ....................................................................................................

7-3

On a UNIX computer, the nine bits of permissions correspond exactly to

nine UNIX permission bits governing read, write, and execute ....

7-3

Volume Information Record ..........................................................................

7-3

File Manager Functions ................................................................................................

7-4

Performing Basic File Operations ..................................................................

7-4

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

7-4

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

7-5

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

7-7

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

7-7

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

7-9

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

7-9

Positioning the Current Position Mark ...........................................................

7-10

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

7-10

LabVIEW Code Interface Reference Manual

x

© National Instruments Corporation

 

Table of Contents

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

7-11

Positioning the End-Of-File Mark .................................................................

7-12

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

7-12

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

7-12

Flushing File Data to Disk .............................................................................

7-13

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

7-13

Determining File, Directory, and Volume Information .................................

7-13

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

7-13

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

7-14

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

7-14

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

7-15

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

7-16

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

7-16

Getting Default Access Rights Information ...................................................

7-17

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

7-17

Creating and Determining the Contents of Directories ..................................

7-17

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

7-17

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

7-18

Copying Files .................................................................................................

7-19

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

7-19

Moving and Deleting Files and Directories ...................................................

7-20

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

7-20

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

7-20

Locking a File Range .....................................................................................

7-21

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

7-21

Matching Filenames with Patterns .................................................................

7-22

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

7-22

Creating Paths ................................................................................................

7-22

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

7-22

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

7-23

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

7-24

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

7-24

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

7-25

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

7-25

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

7-26

Disposing Paths ..............................................................................................

7-27

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

7-27

Duplicating Paths ...........................................................................................

7-27

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

7-27

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

7-27

Extracting Information from a Path ...............................................................

7-28

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

7-28

.........................................................................................................

7-28

© National Instruments Corporation

xi

LabVIEW Code Interface Reference Manual

Table of Contents

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

7-29

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

7-29

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

7-30

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

7-30

Converting Paths to and from Other Representations ....................................

7-31

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

7-31

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

7-32

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

7-32

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

7-33

.........................................................................................................

7-33

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

7-34

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

7-34

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

7-35

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

7-35

Comparing Paths ............................................................................................

7-36

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

7-36

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

7-36

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

7-37

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

7-37

Determining a Path Type ...............................................................................

7-38

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

7-38

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

7-38

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

7-39

Manipulating File Refnums ............................................................................

7-39

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

7-39

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

7-40

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

7-40

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

7-41

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

7-41

Chapter 8

Support Manager Functions

Byte Manipulation Operations .....................................................................................

8-1

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

 

*Macro* .........................................................................................

8-1

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

 

*Macro* .........................................................................................

8-1

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

 

*Macro* .........................................................................................

8-2

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

 

*Macro* .........................................................................................

8-2

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

 

*Macro* .........................................................................................

8-2

LabVIEW Code Interface Reference Manual

xii

© National Instruments Corporation

 

Table of Contents

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

 

*Macro* .........................................................................................

8-2

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

 

*Macro* .........................................................................................

8-3

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

 

*Macro* .........................................................................................

8-3

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

 

*Macro* .........................................................................................

8-3

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

 

*Macro* .........................................................................................

8-3

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

 

*Macro* .........................................................................................

8-4

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

 

*Macro* .........................................................................................

8-4

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

 

*Macro* .........................................................................................

8-4

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

8-5

For THINK C Users .......................................................................................

8-6

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

8-6

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

8-6

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

8-6

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

8-7

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

8-7

String Manipulation .......................................................................................

8-7

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

8-7

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

 

*Macro* .........................................................................................

8-8

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

8-8

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

8-8

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

8-9

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

 

*Macro* .........................................................................................

8-9

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

8-10

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

8-10

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

8-10

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

8-11

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

 

*Macro* .........................................................................................

8-11

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

 

*Macro* .........................................................................................

8-11

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

 

*Macro* .........................................................................................

8-12

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

8-12

© National Instruments Corporation

xiii

LabVIEW Code Interface Reference Manual

Table of Contents

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

8-13

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

8-13

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

8-13

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

8-13

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

 

*Macro* .........................................................................................

8-14

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

8-14

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

 

*Macro* .........................................................................................

8-14

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

8-15

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

8-15

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

8-15

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

 

*Macro* .........................................................................................

8-16

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

8-16

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

8-16

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

8-17

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

8-17

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

 

*Macro* .........................................................................................

8-18

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

8-18

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

8-18

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

8-19

SPrintf

 

SPrintfp

 

PPrintf

 

PPrintfp

 

FPrintf

 

LStrPrintf .......................................................................................

8-19

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

8-22

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

8-22

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

8-22

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

8-23

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

8-23

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

8-23

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

8-24

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

8-24

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

8-24

Utility Functions .............................................................................................

8-25

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

8-25

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

8-26

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

 

*Macro* .........................................................................................

8-26

LabVIEW Code Interface Reference Manual

xiv

© National Instruments Corporation

 

Table of Contents

Time Functions ..............................................................................................

8-27

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

8-27

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

8-27

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

8-28

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

8-28

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

8-29

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

8-29

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

8-30

Appendix A

CIN Common Questions

Appendix B

Customer Communication

Glossary

Figures

Figure 3-1.

Data Storage Spaces for One CIN, Simple Case .....................................

3-2

Figure 3-2.

Three CINs Referencing the Same Code Resource ................................

3-7

Figure 3-3.

Three VIs Referencing a Reentrant VI Containing One CIN .................

3-8

Tables

Table 1-1. Functions with Parameters Needing Pre-allocated Memory ...................

1-38

© National Instruments Corporation

xv

LabVIEW Code Interface Reference Manual

Table of Contents

LabVIEW Code Interface Reference Manual

xvi

© National Instruments Corporation

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