Agilent Technologies 86038A User Manual page 174

Optical dispersion analyzer
Table of Contents

Advertisement

Remote Operation
Example 1: Simple Application for Controlling the ODA
Event Handling
Event handling is added to monitor the ODA events. A very useful event is
a new status message. The status message is shown on the bottom of the
ODA display, which indicates when a sweep has begun, ended, and so on.
By reflecting those messages on the remote application, you provide
invaluable feedback to a user, particularly if they cannot see the ODA
display.
When an event, like a new status message occurs, the ODA informs you by
calling a method on your object. In fact, the ODA will call as many methods
as you care to register – it just keeps a list of functions to call, and runs
through that list when the event occurs.
Implementing events is a little more complicated because Microsoft chose
to use the Delegate mechanism as an abstraction layer between the event
source (the ODA) and the event consumer (your code.) So, instead of
passing a reference to your function to the odaClient, you pass a reference
to your function to a delegate, and then pass the delegate to the odaClient.
To reiterate, you define in your object a function that you wish to be called
when an event occurs. That function has to take the pass parameters
defined by that event – you don't get to choose. Call that function the
event function. Once you have your event function, you instantiate a
delegate for that function. The delegate you use depends on the pass
parameters of the event function. If the event function takes the generic
event pass parameters (an object reference and an EventArgs), you can
use a generic delegate. In general, the event will have customized pass
parameters and you must use the delegate class supplied with the event.
When a class implements a delegate, Microsoft recommends appending
Handler to the name. Some people find this confusing, since in the past
what we have called here the event function (the function you write that
gets called when the event occurs) has also been called the event handler.
Now consider the specific example of a new status message. The
odaClient has an event called NewStatus. The ODA promises to fire it
when a new status message appears. To take advantage of this, l write a
routine called NewStatusEvent
Go into Visual Studio, and select View,
.
Other Windows, Object Browser. Select the Find Symbol tool on the object
browser (look for the binoculars.) Type in NewStatus and click Find. You
get the result below:
The first hit (with the lightning bolt) represents the event itself. The second
hit is the function prototype. NewStatus is expecting a function that
accepts a string and an eEventLogType. Note that the fully qualified
eEventLogType is
Agilent.LWD.Ag86038x.InstrumentObjects.ODACommon.eEventLogType.
174
Agilent 86038A Optical Dispersion Analyzer, Third Edition

Advertisement

Table of Contents
loading

Table of Contents