dotnet_types_and_visa_c_types_reference

Agilent VISA.NET

dotnet_types_and_visa_c_types_reference

VISA Type

.NET Type

Description

ViInt8, ViUInt8, ViChar, ViByte

System.Byte

Since signed bytes are not CLS1-compliant, we use the byte type for both.

ViInt16, ViUInt16

System.Int16

Since unsigned shorts are not CLS-compliant, we use the signed type for both.

ViInt32, ViUInt32

System.Int32

Since unsigned integers are not CLS-compliant, we use the signed type for both.

ViSession, ViPFindList, ViPEvent

System.Int32

Sessions and other VISA object handles are just 32-bit integers.

ViStatus

System.Int32

Status codes (error codes) have always been 32-bit integers.

ViAddr

System.Int32

This is a reference to a remote 32-bit memory space, and will therefore fit in a 32-bit integer

ViBuf

System.String, System.Byte[]

This type represents byte buffers or ASCII strings that are not to be modified by VISA.  The System.String class was chosen for methods that typically write ANSI strings.  .NET automatically marshals the System.String class into ASCII strings that VISA can accept.  For methods that are typically binary data, a byte array was chosen.  It is marshaled such that VISA gets a pointer to the first element of the array.

ViPBuf

System.StringBuilder, System.Byte[]

This type represents byte buffers or ASCII string buffers that are to be written to by VISA.  System.StringBuilder was chosen for functions that typically write ASCII strings, because the default marshalling behavior of that class is to give the C function a pointer to the beginning of the preallocated buffer, and to use the 0 ASCII value to determine the end of the string written in the buffer.  Don't forget to allocate enough storage space in your StringBuilder object.  System.Byte was chosen for functions that often return binary data.  It is marshaled such that VISA gets a pointer to the first element of the array.

ViChar[]

System.StringBuilder

Arrays of ViChar are used when VISA plans to write short-length strings into the passed-in buffer.  Again, System.Stringbuilder is well-suited to acting as a character buffer.

ViAttrState

System.Int32, System.Int16, System.Byte

The value passed to viSetAttribute is an 8-, 16-, or 32-bit integer.

void *

C#: out byte, out short, out int, StringBuilder

VB .NET: ByRef Byte, ByRef Short, ByRef Integer, StringBuilder

viSetAttribute can return 8-, 16-, or 32-bit integers, or strings.  

ViPUInt8, ViPInt8, etc.

C#: out byte, etc

VB .NET: ByRef Byte, etc

The ViPXXXX types, where 'XXXXX' is an integral type, are return values for integer types.  In C#, the 'out' keyword means that the value going in doesn't matter and only the return value matters.  VB .NET does not have the 'out' keyword, so a reference is indicated by using the 'ByRef' keyword.  Therefore, you must initialize values in VB .NET even though they will be overwritten.  The .NET marshalling behavior of 'out' and 'ByRef' is to pass the argument as pointer to the value, which is what VISA is expecting for the ViPXXXX types.

1Common Language Specification.  The specification of the set of types and .NET constructs that are applicable across VB .NET, C#, and all other .NET languages.  API designers or others concerned with compatibility with multiple .NET languages typically limit the types they use to CLS-compliant types.  See the Microsoft Developer Network .NET documentation for more details.