private void DoConnectCOMAPI() { try { // Connect to the Plantronics COM API _sessionManager = new COMSessionManager(); _sessionManager.Register(AppName, out _session); _sessionManagerEvents = (ICOMSessionManagerEvents_Event)_sessionManager; // obtain session manager events interface _sessionManagerEvents.onDeviceStateChanged += _sessionManagerEvents_onDeviceStateChanged; // register for device state changed events (device arrival / removal) _sessionManagerEvents.onCallStateChanged += _sessionManagerEvents_onCallStateChanged; _session.onCallStateChanged += _session_onCallStateChanged; // register for call state changed events (headset call control) _callCommand = _session.GetCallCommand(); // obtain Plantronics object for controlling call state of Plantronics device AttachDevice(); // register for device events and obtain device listener _apiConnected = true; OnSDKInfo(new SDKInfoArgs(SDKInfoType.sdk_connected, "SDK now connected")); } catch (Exception e) { DoTidyUpSDK(_session != null); OnSDKError(new SDKErrorArgs(SDKErrorType.sdk_connection_failed, e.ToString())); DoAttemptReconnectAfterDelay(); } }
/// <summary> /// Instruct Spokes object to connect to Spokes runtime engine and register itself /// so that it can begin to communicate with the attached Plantronics device. /// </summary> /// <param name="SessionName">Optional name of your appplication's session within Spokes runtime engine. If omitted it will default to "COM Session".</param> public bool Connect(string SessionName = "COM Session") { m_sessionName = SessionName; if (!IsSpokesInstalled()) { DebugPrint(MethodInfo.GetCurrentMethod().Name, "FATAL ERROR: cannot connect if Spokes COMSessionManager/SessionCOMManager class is not registered! Spokes not installed (or wrong major version installed for this Spokes Wrapper)!"); throw new Exception("Cannot connect if Spokes COM SessionManager class is not registered! Plantronics Hub not installed!"); } if (isConnected) return true; DeviceCapabilities = new SpokesDeviceCaps(false, false, false, false, false, false, false, false); // we don't yet know what the capabilities are OnCapabilitiesChanged(EventArgs.Empty); bool success = false; try { //////////////////////////////////////////////////////////////////////////////////////// // create session manager, and attach to session manager events m_sessionComManager = new COMSessionManager(); m_sessionManagerEvents = m_sessionComManager as ICOMSessionManagerEvents_Event; if (m_sessionManagerEvents != null) { m_sessionManagerEvents.onCallStateChanged += m_sessionComManager_CallStateChanged; m_sessionManagerEvents.onDeviceStateChanged += m_sessionComManager_DeviceStateChanged; } else success = false; //////////////////////////////////////////////////////////////////////////////////////// // register session to spokes m_sessionComManager.Register(SessionName, out m_comSession); if (m_comSession != null) { // attach to session call events m_sessionEvents = m_comSession as ICOMCallEvents_Event; if (m_sessionEvents != null) { m_sessionEvents.onCallRequested += m_sessionEvents_CallRequested; m_sessionEvents.onCallStateChanged += m_sessionEvents_CallStateChanged; } else success = false; //////////////////////////////////////////////////////////////////////////////////////// // Attach to active device and print all device information // and registers for proximity (if supported by device) AttachDevice(); // note: with latest Hub 3.9 it is hanging here is Hub was only started as a result of my COM request!!!!! success = true; } } catch (System.Exception e) { success = false; throw new Exception("Failed to connect to Spokes", e); } return success; }
private static int _callid; // variable to track call id between my app and Plantronics static void Main() { Console.WriteLine("C# Plantronics COM API Sample"); bool quit = false; // Connect to the Plantronics COM API _sessionManager = new COMSessionManager(); _sessionManager.Register("My App", out _session); _sessionManagerEvents = (ICOMSessionManagerEvents_Event)_sessionManager; // obtain session manager events interface _sessionManagerEvents.onDeviceStateChanged += _sessionManagerEvents_onDeviceStateChanged; // register for device state changed events (device arrival / removal) _session.onCallStateChanged += _session_onCallStateChanged; // register for call state changed events (headset call control) _callCommand = _session.GetCallCommand(); // obtain Plantronics object for controlling call state of Plantronics device AttachDevice(); // register for device events and obtain device listener while (!quit) { ShowMenu(); string cmd = Console.ReadLine(); switch (cmd) { case "1": _callid++; DoIncomingCall(_callid, "Bob%20Smith"); // inform Plantronics my app has an incoming (ringing) call break; case "2": _callid++; DoOutgoingCall(_callid, "Bob%20Smith"); // inform Plantronics my app has an outgoing call break; case "3": DoAnswerCall(_callid); // inform Plantronics my app has now answered an incoming (ringing) call break; case "4": DoHoldCall(_callid); // place call on hold break; case "5": DoResumeCall(_callid); // resume the call break; case "6": DoMuteCall(true); // mute the headset (note for wireless products, audio link must be active) break; case "7": DoMuteCall(false); // unmute the headset (note for wireless products, audio link must be active) break; case "8": DoTerminateCall(_callid); // inform Plantronics my app has now terminated the call break; case "0": quit = true; break; default: Console.WriteLine("Unrecognised menu choice."); break; } } // Cleanup the Plantronics COM API DetachDevice(); _session.onCallStateChanged -= _session_onCallStateChanged; _sessionManagerEvents.onDeviceStateChanged -= _sessionManagerEvents_onDeviceStateChanged; _sessionManager.Unregister(_session); Marshal.ReleaseComObject(_session); Marshal.ReleaseComObject(_sessionManager); }