Keysight VISA.NET Help
Hardware Events

Hardware Events

VISA.NET sessions use VISA.NET hardware events to report things that the calling program may need to know about. For the most part, these events are related to the I/O hardware associated with the session – interrupts, service requests, triggers, and so on. These events are called hardware events to distinguish them from notifications connected with asynchronous I/O. Refer to Asynchronous I/O for details regarding asynchronous I/O events.

VISA C provides a number of functions that enable calling programs to:

These functions have an event type parameter that identifies the type of event.

VISA.NET provides equivalent functionality in two forms:

Event Methods

IVisaSession, the base interface for all sessions, contains methods that enable the calling program to:

Each method includes an EventType argument that indicates the kind of event to which the method call applies.

There are several overloads to the WaitOnEvent method. The most basic only takes an EventType argument, but others take a timeout argument to avoid blocking indefinitely, and a status that tells the status of the event queue.

VISA.NET event methods are only recommended when blocking waits are required.

Not all events apply to all sessions. When using the event methods and specifying the eventType, make sure that the event specified by eventType applies to the session interface that is being used.

.NET Events

.NET events provide callback delegates, registration methods, and a notification mechanism that are specific to the particular event. Events are declared only in the session interfaces in which they can be used. Note that .NET events do not implement a blocking wait mechanism. They are recommended when blocking waits are not required.

The following interfaces declare .NET events:

Event Arguments for .NET Events

Event arguments classes, also called event args classes, communicate information related to a .NET event. Like all .NET event args classes, the base VISA.NET events args class, VisaEventArgs, derives from System.EventArgs. There are several other specialized event args classes in VISA.NET, all of which derive from VisaEventArgs:

These event args classes are named for the events that use them. Each event args class exposes additional information that is specific to that particular event type. When a .NET event is fired, the event handler (essentially a callback method) is called, and the second parameter is an event args reference.

Calling programs must register a handler with a .NET event in order to receive event notifications. For example, if your program uses a GPIB interface session, you need to to define the handler that is called when the event is fired:

Define Event Handler
Copy Code
private static void CicEventHandler(object src, GpibControllerInChargeEventArgs args) 
   {
      // Code to handle the event … 
   } 

and then register the handler for the ControllerInCharge event before you will receive notifications:

Register the Handler
Copy Code
gpibIntfcSession.ControllerInCharge += new EventHandler(CicEventHandler);

Event Arguments for Event Methods

Event methods return a VisaEventArgs reference, which you can then cast to the event arguments class (listed above) corresponding to the type of event that was fired. When using event methods, always inspect the event type of an event args class before casting it to a more specific event arguments type. For example, suppose your program uses a GPIB interface session and has enabled EventType.GpibControllerInCharge events. Now suppose that your program executes the following code:

VisaEventArgs args = gpibIntfcSession.WaitOnEvent(EventType.GpibControllerInCharge);

To be safe, check to make sure that the event is a GPIB controller in charge event before casting to the corresponding event args class:

GpibControllerInChargeEventArgs cicArgs;
if (args.EventType == EventType.GpibControllerInCharge)
{
    cicArgs = (GpibControllerInChargeEventArgs)args;
    Boolean inCharge = cicArgs.IsControllerInCharge;
}

Once your program has the reference to GpibControllerInChargeEventArgs, it can access the IsControllerInCharge property, which is specific to that event.

 

 


© Keysight Technologies 2015-2025