Click or drag to resize

Adding an Event

To add an event to a driver

  1. From Solution Explorer, double-click the Driver Designer node under the Nimbus node.

  2. The IVI.NET Driver Designer tree view opens.

  3. Expand the root node, which will be named after the driver assembly (e.g.: Acme.Acme4321).

  4. Locate and then select the desired class, struct, or interface where the new event is desired.

  5. Right-click on the selected node and choose Add Event.

  6. A new event is added with a default name and the tree node enters edit mode. By default the event type is EventHandler. See the section below on Understanding Event Types to learn more about events and delegate types in Nimbus.

  7. With the event node still in edit mode, type the desired name of the event followed by a colon (:) followed by the name of the event type, and hit the Enter key. The colon and event type can be excluded if the default EventHandler delegate type.

    Note Note

    Refer to the help topic Understanding Type Name Resolution in Nimbus for more information regarding how Nimbus resolves type names entered into the designer.

    When choosing an event name, the following naming rules apply:

    • The name must be unique within its containing type. It need not be unique across the entire driver.

    • The name must contain only alphanumeric characters.

    • Spaces are not allowed.

    • The name must begin with an alphabetic character.

  8. After the event is added, the IVI.NET Event General Editor appears in the right portion of the IVI.NET Driver Designer. See the help topic for that Item Editor for details on defining the event further.

Understanding Event Types

.NET events must always be of type delegate. By default, Nimbus creates new events with the existing EventHandler delegate type from the .NET Framework. This type has been around since .NET 1.1, so it is a reasonable default choice for IVI.NET drivers targeting .NET Framework 2.0. However, many events in IVI.NET drivers will need to communicate driver-specific data to the client when firing the event. The EventHandler delegate is quite limited in this regard, so typically driver developers will need to change the event type to something with richer semantics.

There are a few basic approaches to designing event types in .NET components. In early versions of .NET, the typical solution would be to create an entirely new delegate type for each unique event. However, current .NET design guidelines strongly favor using existing delegate types from the .NET Framework and customizing the signature of that delegate type. Because the creation of custom delegates is discouraged, Nimbus does not support the creation of these types from the Driver Designer.

The approach taken for designing events depends upon the .NET Framework version the IVI.NET driver is targeting:

  • For IVI.NET drivers targeting .NET Framework 2.0, the recommended approach is to use the EventHandler<T> generic delegate type along with a driver-defined EventArgs class. This is accomplished by adding a class to the driver using the Driver Designer, taking care that the class derives from EventArgs. The newly created EventArgs-derived class can be augmented with whatever properties are desired.

  • For IVI.NET drivers targeting .NET Framework 3.5 or greater, the recommended approach is to use either the Action<T> or Func<T> generic delegate types. This approach supports the ability to use delegates that take up to 16 parameters of any type. Thus, there is no need to create a special EventArgs-derived class to carry event data. This simplifies the code that clients need to write when fielding such events.

See Also

Download a complete CHM version of this documentation here.