VISA COM Interfaces vs. VISA COM Objects

COM makes an important distinction between COM interfaces and COM objects.  The COM object is the "thing" that you are using, and COM interfaces are "views" on that thing.  To reduce complexity, many COM objects only have one COM interface that is meant to be used, or all of the interfaces on the object are on a single inheritance chain, but VISA COM is designed differently.  A VISA COM object can have multiple interfaces that have very little in common.  

An example is provided by two of the interfaces on the VISA COM I/O ASRL::INSTR resource, ISerial and IMessage.  They both derive from IVisaSession, so they both support all of IVisaSession's methods and properties, but other than that they have little in common.  IMessage is meant for reading and writing strings between the PC and the instrument, and the ISerial interface is meant for setting serial properties, like the baud rate.  Most resource types support the IMessage interface, so you can read and write to them without worrying about what I/O connection is being used, but occasionally you must do things that are specific to the I/O type, like change the baud rate.  

If you had an interface to IMessage, but needed to change an RS-232 property, you would use the following code in Microsoft Visual Basic:

'First create the session we will use
Dim msg as IMessage
Dim rm As VisaComLib.ResourceManager
Set msg =rm.Open("ASRL1::INSTR")

' Oops, we forgot to set the baud rate
Dim rs232 as ISerial
Set  rs232 = msg
rs232.BaudRate = 9600
rs232.TerminationCharacter = 10
rs232.TerminationCharacterEnabled = True
rs232.FlowControl = ASRL_FLOW_NONE

' Now we can use IMessage to read and write to the instrument
msg.WriteString("*IDN?" & vblf)
MsgBox msg.ReadString(1000)

Setting the rs232 variable to the msg variable does not copy the object and create a new one; it just lets you use the other COM interface on the VISA COM I/O Resource Session COM object you created with the rm.Open() call. You can think of interfaces as different "views" on the same object; setting one interface to another just asks the object if it supports the interface, and if so, gives you the ability to use the new interface on the same object.

It is not easy to tell, just by looking at the list of VISA COM I/O interfaces, which ones are available for each VISA COM I/O resource session you create. The Supported VISA COM I/O Resource Classes topic explains which VISA COM I/O interfaces are supported by each VISA COM I/O resource class.

See Also

Creating and Finding Resource Session Objects
Supported VISA COM I/O Resource Classes
Diagram of VISA COM Interfaces