- •Important Information
- •Warranty
- •Copyright
- •Trademarks
- •Organization of This Manual
- •Conventions Used in This Manual
- •Related Documentation
- •Customer Communication
- •Introduction
- •Classes of External Code
- •Supported Languages
- •Macintosh
- •Microsoft Windows 3.1
- •Microsoft Windows 95 and Windows NT
- •Solaris
- •Steps for Creating a CIN
- •1. Place the CIN on a Block Diagram
- •2. Add Input and Output Terminals to the CIN
- •Input-Output Terminals
- •Output-Only Terminals
- •3. Wire the Inputs and Outputs to the CIN
- •4. Create .c File
- •Special Macintosh Considerations
- •5. Compile the CIN Source Code
- •Macintosh
- •THINK C for 68K (Versions 5-7)
- •Symantec C++ 8.0 for Power Macintosh
- •Metrowerks CodeWarrior for 68K
- •Metrowerks CodeWarrior for Power Macintosh
- •Microsoft Windows 3.x
- •Watcom C Compiler
- •Microsoft Windows 95 and Windows NT
- •Microsoft SDK C/C++ Compiler
- •Visual C++ for Windows 95 or Windows NT
- •Solaris 1.x
- •Solaris 2.x
- •6. Load the CIN Object Code
- •LabVIEW Manager Routines
- •Online Reference
- •Pointers as Parameters
- •Debugging External Code
- •DbgPrintf
- •Debugging CINs Under Windows 95 and Windows NT
- •Debugging CINs Under Sun or Solaris
- •Debugging CINs Under HP-UX
- •Introduction
- •CIN .c File
- •How LabVIEW Passes Fixed Sized Data to CINs
- •Scalar Numerics
- •Scalar Booleans
- •Refnums
- •Clusters of Scalars
- •Return Value for CIN Routines
- •Examples with Scalars
- •1. Place the CIN on the Block Diagram
- •2. Add Two Input and Output Terminals to the CIN
- •3. Wire the Inputs and Outputs to the CIN
- •4. Create the CIN Source Code
- •5. Compile the CIN Source Code
- •Macintosh
- •THINK C for 68K and Symantec C++
- •Microsoft Windows 3.x
- •Watcom C Compiler
- •Microsoft Windows 95 and Windows NT
- •Microsoft SDK Compiler
- •Microsoft Visual C++ Compiler
- •Solaris 1.x, Solaris 2.x, and HP-UX
- •6. Load the CIN Object Code
- •Comparing Two Numbers, Producing a Boolean Scalar
- •How LabVIEW Passes Variably Sized Data to CINs
- •Alignment Considerations
- •Arrays and Strings
- •Paths (Path)
- •Clusters Containing Variably Sized Data
- •Resizing Arrays and Strings
- •SetCINArraySize
- •NumericArrayResize
- •Examples with Variably Sized Data
- •Concatenating Two Strings
- •Working with Clusters
- •CIN Routines
- •Data Spaces and Code Resources
- •CIN Routines: The Basic Case
- •Loading a VI
- •Unloading a VI
- •Loading a New Resource into the CIN
- •Compiling a VI
- •Running a VI
- •Saving a VI
- •Aborting a VI
- •Multiple References to the Same CIN
- •Reentrancy
- •Code Globals and CIN Data Space Globals
- •Examples
- •Using Code Globals
- •Using CIN Data Space Globals
- •Calling a Windows 3.1 Dynamic Link Library
- •Calling a 16-Bit DLL
- •1. Load the DLL
- •2. Get the address of the desired function
- •3. Describe the function
- •4. Call the function
- •Example: A CIN that Displays a Dialog Box
- •The Block Diagram
- •The CIN Code
- •Compiling the CIN
- •Optimization
- •Introduction
- •Creating Shared External Subroutines
- •External Subroutine
- •Macintosh
- •THINK C Compiler and CodeWarrior 68K Compiler
- •MPW Compiler
- •Solaris 1.x, Solaris 2.x, and HP-UX
- •Calling Code
- •Macintosh
- •THINK C Compiler
- •CodeWarrior 68K Compiler
- •MPW Compiler
- •Solaris 1.x, Solaris 2.x, and HP-UX
- •Simple Example
- •External Subroutine Example
- •Compiling the External Subroutine
- •Macintosh
- •THINK C Compiler and CodeWarrior 68K Compiler
- •MPW Compiler
- •Microsoft Windows 3.1
- •Watcom C Compiler
- •Microsoft Windows 95 and Windows NT
- •Solaris 1.x, Solaris 2.x, and HP-UX
- •Calling Code
- •Compiling the Calling Code
- •Macintosh
- •THINK C Compiler
- •CodeWarrior 68K Compiler
- •MPW Compiler
- •Microsoft Windows 3.1
- •Watcom C Compiler
- •Microsoft Windows 95 and Windows NT
- •Solaris 1.x, Solaris 2.x, and HP-UX
- •Introduction
- •Basic Data Types
- •Scalar Data Types
- •Booleans
- •Numerics
- •Complex Numbers
- •char Data Type
- •Dynamic Data Types
- •Arrays
- •Strings
- •C-Style Strings (CStr)
- •Pascal-Style Strings (PStr)
- •LabVIEW Strings (LStr)
- •Concatenated Pascal String (CPStr)
- •Paths (Path)
- •Memory-Related Types
- •Constants
- •Memory Manager
- •Memory Allocation
- •Static Memory Allocation
- •Dynamic Memory Allocation: Pointers and Handles
- •Memory Zones
- •Using Pointers and Handles
- •Simple Example
- •Reference to the Memory Manager
- •Memory Manager Data Structures
- •File Manager
- •Introduction
- •Identifying Files and Directories
- •Path Specifications
- •Conventional Path Specifications
- •Empty Path Specifications
- •LabVIEW Path Specification
- •File Descriptors
- •File Refnums
- •Support Manager
- •Allocating and Releasing Handles
- •Allocating and Releasing Pointers
- •Manipulating Properties of Handles
- •AZHLock
- •AZHPurge
- •AZHNoPurge
- •AZHUnlock
- •Memory Utilities
- •ClearMem
- •MoveBlock
- •SwapBlock
- •Handle and Pointer Verification
- •Memory Zone Utilities
- •File Manager Data Structures
- •File/Directory Information Record
- •File Type Record
- •Path Data Type
- •Permissions
- •Volume Information Record
- •File Manager Functions
- •Performing Basic File Operations
- •FCreate
- •FCreateAlways
- •FMClose
- •FMOpen
- •FMRead
- •FMWrite
- •Positioning the Current Position Mark
- •FMSeek
- •FMTell
- •Positioning the End-Of-File Mark
- •FGetEOF
- •FSetEOF
- •Flushing File Data to Disk
- •FFlush
- •FExists
- •FGetAccessRights
- •FGetInfo
- •FGetVolInfo
- •FSetAccessRights
- •FSetInfo
- •Getting Default Access Rights Information
- •FGetDefGroup
- •FListDir
- •FNewDir
- •Copying Files
- •FCopy
- •Moving and Deleting Files and Directories
- •FMove
- •FRemove
- •Locking a File Range
- •FLockOrUnlockRange
- •Matching Filenames with Patterns
- •FStrFitsPat
- •Creating Paths
- •FAddPath
- •FAppendName
- •FAppPath
- •FEmptyPath
- •FMakePath
- •FNotAPath
- •FRelPath
- •Disposing Paths
- •FDisposePath
- •Duplicating Paths
- •FPathCpy
- •FPathToPath
- •Extracting Information from a Path
- •FDepth
- •FDirName
- •FName
- •FNamePtr
- •FVolName
- •FArrToPath
- •FFlattenPath
- •FPathToArr
- •FPathToAZString
- •FPathToDSString
- •FStringToPath
- •FTextToPath
- •FUnFlattenPath
- •Comparing Paths
- •FIsAPath
- •FIsAPathOrNotAPath
- •FIsEmptyPath
- •FPathCmp
- •Determining a Path Type
- •FGetPathType
- •FIsAPathOfType
- •FSetPathType
- •Manipulating File Refnums
- •FDisposeRefNum
- •FIsARefNum
- •FNewRefNum
- •FRefNumToFD
- •FRefNumToPath
- •Byte Manipulation Operations
- •Mathematical Operations
- •For THINK C Users
- •RandomGen
- •String Manipulation
- •BlockCmp
- •CPStrCmp
- •CPStrIndex
- •CPStrInsert
- •CPStrRemove
- •CPStrReplace
- •CPStrSize
- •CToPStr
- •HexChar
- •IsAlpha
- •IsDigit
- •IsLower
- •IsUpper
- •LStrCmp
- •LToPStr
- •PPStrCaseCmp
- •PPStrCmp
- •PStrCaseCmp
- •PStrCat
- •PStrCmp
- •PStrCpy
- •PStrNCpy
- •PToCStr
- •PToLStr
- •StrCat
- •StrCmp
- •StrCpy
- •StrLen
- •StrNCaseCmp
- •StrNCmp
- •StrNCpy
- •ToLower
- •ToUpper
- •Utility Functions
- •BinSearch
- •QSort
- •Time Functions
- •ASCIITime
- •DateCString
- •DateToSecs
- •MilliSecs
- •SecsToDate
- •TimeCString
- •TimeInSecs
- •Microsoft Windows 3.1, Windows 95, and Windows NT
- •Macintosh
- •How do I debug my CIN?
- •Can LabVIEW be used to call a DLL in Windows?
- •Glossary
- •Index
Chapter 2 CIN Parameter Passing
LabVIEW stores strings in memory as one-dimensional arrays of unsigned 8-bit integers.
LabVIEW stores Boolean arrays in memory as a series of bits packed to the nearest 16-bit word. LabVIEW ignores unused bits in the last word. LabVIEW orders the bits from left to right; that is, the most significant bit (MSB) is index 0. As with other arrays, a 4-byte dimension size precedes Boolean arrays. The dimension size for Boolean arrays indicates the number of Booleans contained in the array.
Paths (Path)
The exact structure for Path data types is subject to change in future versions of LabVIEW. A Path is a dynamic data structure that LabVIEW passes the same way it passes arrays. LabVIEW stores the data for Paths in an application zone handle. See the Online Reference, accessed from LabVIEW’s Help window, or the Code Interface Node Reference online manual for descriptions of the functions that manipulate Paths.
Clusters Containing Variably Sized Data
For cluster arguments, LabVIEW passes a pointer to a structure containing the elements of the cluster. LabVIEW stores scalar values directly as components inside the structure. If a component is another cluster, LabVIEW stores this cluster value as a component of the main cluster. If a component is an array or string, LabVIEW stores a handle to the array or string component in the structure.
Resizing Arrays and Strings
You can use the LabVIEW SetCINArraySize routine to resize return arrays and strings that you pass to a CIN. You pass the function the handle that you want to resize, information that describes the data structure, and the desired size of the array or handle. The function takes into account any padding and alignment needed for the data structure. The function does not, however, update the dimension fields in the array. If you successfully resize the array, you need to update the dimension fields to correctly reflect the number of elements in the array.
You can resize numeric arrays more easily with
NumericArrayResize. You pass to this function the array you
LabVIEW Code Interface Reference Manual |
2-12 |
© National Instruments Corporation |
Chapter 2 CIN Parameter Passing
want to resize, a description of the data structure, and information about the new size of the array.
When you resize arrays of variably-sized data (for example, arrays of strings) with the SetCINArraySize or NumericArrayResize routines, you should be aware of the following facts. If the new size of the array is smaller, LabVIEW disposes of the handles used by the disposed element. Neither function sets the dimension field of the array. You must do this in your code after the function call. If the new size is larger, however, LabVIEW does not automatically create the handles for the new elements. You have to create these handles after the function returns.
The SetCINArraySize and NumericArrayResize functions are described in the following sections
SetCINArraySize
syntax |
MgErr |
SetCINArraySize |
(UHandle dataH, int32 |
|
|
paramNum, int32 |
newNumElmts); |
SetCINArraySize resizes a data handle based on the data structure of an argument that you pass to the CIN. It does not set the array dimension field.
Parameter |
Type |
Description |
|
|
|
|
|
|
dataH |
UHandle |
The handle that you want to resize. |
paramNum |
int32 |
The number for this parameter in the |
|
|
argument list to the CIN. The leftmost |
|
|
parameter has a parameter number of 0, |
|
|
and the rightmost has a parameter |
|
|
number of n-1, where n is the total |
|
|
number of parameters |
newNumElmts |
int32 |
The new number of elements to which |
|
|
the handle should refer. For a one- |
|
|
dimensional array of five values, you |
|
|
pass a value of 5 for this argument. For a |
|
|
two-dimensional array of two rows by |
|
|
three columns, you pass a value of 6 for |
|
|
this argument. |
|
|
|
© National Instruments Corporation |
2-13 |
LabVIEW Code Interface Reference Manual |
Chapter 2 CIN Parameter Passing
returns |
MgErr, which can contain the errors in the following list. MgErrs are |
|
|
discussed in Chapter 5, Manager Overview. |
|
|
|
|
|
Error |
Description |
|
|
|
|
|
|
|
noErr |
No error. |
|
mFullErr |
Not enough memory to perform operation |
|
mZoneErr |
Handle is not in specified zone. |
|
|
|
NumericArrayResize
syntax |
MgErr |
NumericArrayResize(int32 typeCode, int32 |
|
|
numDims, UHandle *dataHP, int32 |
|
|
totalNewSize); |
NumericArrayResize resizes a data handle that refers to a numeric array. This routine also accounts for alignment issues. It does not set the array dimension field. If *dataHP is NULL, LabVIEW allocates a new array handle in *dataHP.
Parameter |
Type |
Description |
|
|
|
|
|
|
typeCode |
int32 |
Describes the data type for the array that |
|
|
you want to resize. The header file |
|
|
extcode.h defines the following |
|
|
constants for this argument |
|
|
iB Data is an array of signed 8-bit |
|
|
integers. |
|
|
iW is an array of signed 16-bit integers. |
|
|
iL Data is an array of signed 32-bit |
|
|
integers. |
|
|
uB Data is an array of unsigned 8-bit |
|
|
integers. |
|
|
uW Data is an array of unsigned 16-bit |
|
|
integers. |
|
|
uL Data is an array of unsigned 32-bit |
|
|
integers. |
|
|
fS Data is an array of single-precision |
|
|
(32-bit) numbers. |
|
|
|
LabVIEW Code Interface Reference Manual |
2-14 |
© National Instruments Corporation |
Chapter 2 CIN Parameter Passing
Parameter |
Type |
Description |
|
|
|
|
|
|
|
|
fD Data is an array of double-precision |
|
|
(64-bit) numbers. |
|
|
fX Data is an array of extended- |
|
|
precision numbers. |
|
|
cS Data is an array of single-precision |
|
|
complex numbers. |
|
|
cD Data is an array of double-precision |
|
|
complex numbers. |
|
|
cX Data is an array of extended- |
|
|
precision complex numbers. |
numDims |
int32 |
The number of dimensions in the data |
|
|
structure to which the handle refers. |
|
|
Thus, if the handle refers to a |
|
|
two-dimensional array, you pass a |
|
|
value of 2 for numDims. |
*dataHP |
UHandle |
A pointer to the handle that you want to |
|
|
resize. If this is a pointer to NULL, |
|
|
LabVIEW allocates and sizes a new |
|
|
handle appropriately and returns the |
|
|
handle in *dataHP. |
|
|
|
totalNewSize |
int32 |
The new number of elements to which |
|
|
the handle should refer. For a |
|
|
unidimensional array of five values, |
|
|
you pass a value of 5 for this argument. |
|
|
For a two-dimensional array of two |
|
|
rows by three columns, you pass a |
|
|
value of 6 for this argument. |
|
|
|
returns |
MgErr, which can contain the errors in the following list. |
|
|
|
|
|
Error |
Description |
|
|
|
|
|
|
|
noErr |
No error. |
|
mFullErr |
Not enough memory to perform operation |
|
mZoneErr |
Handle is not in specified zone. |
|
|
|
© National Instruments Corporation |
2-15 |
LabVIEW Code Interface Reference Manual |