First Steps Code Sample
Download ZIP of this example

Connect to the Plantronics COM API:

myAppName = "SDK .NET COM sample"; // Define your own app name string for later
sessionManager = new COMSessionManager();
sessionManager.Register(myAppName, out session);

Hook to SessionManager events:

sessionManagerEvents = sessionManager as ICOMSessionManagerEvents_Event;
if (sessionManagerEvents != null)
    sessionManagerEvents.onCallStateChanged += SessionManagerEvents_onCallStateChanged;
    sessionManagerEvents.onDeviceStateChanged += SessionManagerEvents_onDeviceStateChanged;

Obtain a CallCommand object, get the primary Plantronics device (if any) and then register for any device event handlers you require:

if (session != null)
    callCommand = session.GetCallCommand(); // Obtain a CallCommand object for later use
    device = session.GetActiveDevice();
    deviceEvents = device as ICOMDeviceEvents_Event;
    if (deviceEvents != null)
        deviceEvents.onMuteStateChanged += onMuteStateChanged;
    deviceListener = device.DeviceListener; // Obtain a DeviceListener object for later use

That's it, you're all connected!

Now here's how to do some common call control tasks...

  • Detect that a Plantronics device was plugged in or unplugged from the computer:
    Important: this step must be done to ensure the integration works well with Plantronics
To handle this case you need to put some code into the SessionManager DeviceStateChanged event handler (registered earlier) to detach from then re-attach the device, as follows:
private void SessionManagerEvents_onDeviceStateChanged(COMStateDeviceEventArgs deviceEventArgs)
    // This event handler is fired when primary Plantronics device changes (device
    // is plugged in / unplugged.
    // Calling DetachDevice and AttachDevice will effectively unregister and re-register the 
    // device event handlers.
Note: the code in AttachDevice will hook device event handlers like shown above, and DetachDevice will unhook them. To see a detailed example download the ZIP of this example.
  • Tell Plantronics your app has an incoming call:
COMCall call = new COMCall() { Id = ++callId };
Contact contact = new Contact() { Name = "noname" };
callCommand.IncomingCall(call, contact, CallRingTone.RingTone_Unknown,

Note: the above requires you to define this convenience class:

class Contact : COMContact
    public string Email { get; set; }
    public string FriendlyName { get; set; }
    public string HomePhone { get; set; }
    public int Id { get; set; }
    public string MobilePhone { get; set; }
    public string Name { get; set; }
    public string Phone { get; set; }
    public string SipUri { get; set; }
    public string WorkPhone { get; set; }
  • Tell Plantronics your app has an outgoing call:
COMCall call = new COMCall() { Id = ++callId };
Contact contact = new Contact() { Name = "noname" };
callCommand.OutgoingCall(call, contact, CallAudioRoute.AudioRoute_ToHeadset);
  • Tell Plantronics that your app has answered an incoming call (user answered via your app's GUI):
COMCall call = new COMCall() { Id = callId };
  • Tell Plantronics that your app has placed the call on hold:
COMCall call = new COMCall() { Id = callId };
  • Tell Plantronics that your app has resumed the call:
COMCall call = new COMCall() { Id = callId };
  • Tell Plantronics that your app has terminated the call (or rejected an incoming call):
COMCall call = new COMCall() { Id = callId };
  • Tell Plantronics that your app has gone on mute:
deviceListener.mute = true;
  • Tell Plantronics that your app has come off mute:
deviceListener.mute = false;
  • Listen for CallState events to know what calling state Plantronics headset is in and for which call (integer call id used earlier in CallCommand IncomingCall/OutgoingCall):
private void SessionManagerEvents_onCallStateChanged(COMCallEventArgs callEventArgs)
    // Plantronics API has sent us a call state changed event.
    // If it is for our application then update our GUI with this call state
    // information.
    if (callEventArgs.CallSource == myAppName)
        // callEventArgs.CallState tells me the current calling state that my Plantronics headset is in
        // tells me the integer call id this calling state refers to
        // I can use this information to syncronize with my app
        switch (callEventArgs.CallState)
            case CallState.CallState_CallRinging:
            case CallState.CallState_AcceptCall:
            case CallState.CallState_CallInProgress:
            case CallState.CallState_HoldCall:
            case CallState.CallState_Resumecall:
            case CallState.CallState_TransferToHeadSet:
            case CallState.CallState_TransferToSpeaker:
                // todo - this means we are in a call
            case CallState.CallState_CallEnded:
            case CallState.CallState_AnsweredAndEnded:
            case CallState.CallState_UnansweredAndEnded:
            case CallState.CallState_CallIdle:
            case CallState.CallState_RejectCall:
            case CallState.CallState_TerminateCall:
                // todo - this means we are not in a call
                // ignore other call state events for now
  • Listen for MuteStateChanged events to know when Plantronics headset has changed its microphone mute:
private void onMuteStateChanged(COMDeviceEventArgs args)
    // todo - use args.mute to update your app to reflect device's current mute state

That's it! If you are looking for other languages or our smarter headset features check out our API Overview, API Reference, Code Samples.

Still got questions? Post them on the forum.


News Articles Classification: