Wednesday, February 08, 2006

C# Sample

Below is a brief walkthrough of what I did to put the C# sample together. I put it together with the Microsoft Visual C# .NET part of Visual Studio 2003, your mileage may vary. I'd also like to point out that I don't have much knowledge or experience with C#, but was nonetheless surprised by how easy it was to put a fully functioning sample application together.

The first thing to do is add a reference to Plantronics Device. The entry you are looking for is "PlantronicsDevice 1.0 Type Library" under the COM tab on the add reference dialog. If you can't find it there for some reason, you can also browse to the type library which was installed as part of the SDK (it's at C:\program files\plantronics\plantronics device\sdk\lib\_PlantronicsDevice.tlb by default).

Next add a using directive to your code.

using PlantronicsDevice;

Now, you need a class that is going to receive the event notifications, in the sample it is just the TestPlantronicsDeviceCSharp form class. Just add IDeviceEvents to the list of classes from which yours inherits.

public class TestPlantronicsDeviceCSharp :
System.Windows.Forms.Form,
IDeviceEvents

Now, you'll want to get the plug-and-play watcher up and running so you can get DeviceAttached and DeviceDetached events. This is easy enough though; it can be acomplished in one line, probably in your class's constructor.

plantronicsDevice.StartupPNP();

The next thing to do is get your event handler functions in place. The object browser in conjunction with the PlantronicsDevice reference will show you what the function arguments need to look like.

You need to write a function for each one you want to do something with.

#region IDeviceEvents Members

public void AudioEnabledChanged(object pSender, bool bAudioEnabled)
{
checkAudioEnabled.Checked = bAudioEnabled;
}

public void TalkPressed(object pSender)
{
checkTalk.Checked = true;
}

//...

#endregion

Finally, the last thing you need to do is hook up these functions to the events being generated by the Plantronics device modules. A simple += somewhere, probably in your class's constructor, is all it takes.

plantronicsDevice.AudioEnabledChanged += new IDeviceEvents_AudioEnabledChangedEventHandler(AudioEnabledChanged);
plantronicsDevice.TalkPressed += new IDeviceEvents_TalkPressedEventHandler(TalkPressed);

For events headed the other way, like controlling the ringer and the audio link, it is even easier. They're just properties you can address directly.

plantronicsDevice.AudioEnabled = true

0 Comments:

Post a Comment

<< Home