Exemplo n.º 1
0
        private void AttachDevice()
        {
            // Lets get the primary Plantronics device (if any) and then register
            // for the device event handlers
            try
            {
                _device = _session.GetActiveDevice();
                if (_device != null)
                {
                    // display device information:
                    OnSDKInfo(new SDKInfoArgs(SDKInfoType.sdk_device_attached, "Device attached: " + _device.ProductName + ", Product ID = " + _device.ProductId.ToString("X")));

                    _deviceListenerEvents = (ICOMDeviceListenerEvents_Event)_device.DeviceListener;
                    if (_deviceListenerEvents != null)
                    {
                        _deviceListenerEvents.onHeadsetStateChanged += _deviceListenerEvents_onHeadsetStateChanged;
                        _deviceListenerEvents.onATDStateChanged     += _deviceListenerEvents_onATDStateChanged;

                        OnSDKInfo(new SDKInfoArgs(SDKInfoType.sdk_notification, "Successfully hooked to device listener events"));
                    }
                    else
                    {
                        OnSDKInfo(new SDKInfoArgs(SDKInfoType.sdk_notification, "Unable to hook to device listener events"));
                    }

                    _deviceListener = _device.DeviceListener; // Obtain a DeviceListener object for later use

                    _deviceComEvents = _device as ICOMDeviceEvents_Event;
                    if (_deviceComEvents != null)
                    {
                        // Attach to device events
                        _deviceComEvents.onButtonPressed     += _deviceComEvents_onButtonPressed;
                        _deviceComEvents.onMuteStateChanged  += _deviceComEvents_onMuteStateChanged;
                        _deviceComEvents.onDataReceived      += _deviceComEvents_onDataReceived;
                        _deviceComEvents.onAudioStateChanged += _deviceComEvents_onAudioStateChanged;

                        OnSDKInfo(new SDKInfoArgs(SDKInfoType.sdk_notification, "AttachedEventHandler to device events"));
                    }
                    else
                    {
                        OnSDKInfo(new SDKInfoArgs(SDKInfoType.sdk_notification, "Error: unable to attach to device events"));
                    }

                    OnSDKInfo(new SDKInfoArgs(SDKInfoType.sdk_notification, "Device mute state: muted = " + _deviceListener.mute)); // Obtain initial device microphone mute state
                }
                else
                {
                    OnSDKInfo(new SDKInfoArgs(SDKInfoType.sdk_notification, "Unable to retrieve active device"));
                }
            }
            catch (Exception)
            {
                OnSDKInfo(new SDKInfoArgs(SDKInfoType.sdk_notification, "Unable to retrieve/hook to active device"));
            }
        }
Exemplo n.º 2
0
        private static void AttachDevice()
        {
            // Lets get the primary Plantronics device (if any) and then register
            // for the device event handlers
            try
            {
                _device = _session.GetActiveDevice();
                if (_device != null)
                {
                    // display device information:
                    Console.WriteLine("Device attached: " + _device.ProductName + ", Product ID = " + _device.ProductId.ToString("X"));

                    _deviceListenerEvents = (ICOMDeviceListenerEvents_Event)_device.DeviceListener;
                    if (_deviceListenerEvents != null)
                    {
                        _deviceListenerEvents.onHeadsetStateChanged += _deviceListenerEvents_onHeadsetStateChanged;

                        Console.WriteLine("Successfully hooked to device listener events");

                        // Mobile Caller ID: onDataReceived event handler to receive BT600 mobile caller id
                        _deviceComEvents = (ICOMDeviceEvents_Event)_session.GetActiveDevice();
                        if (_deviceComEvents != null)
                        {
                            _deviceComEvents.onDataReceived += _deviceComEvents_onDataReceived;
                        }
                    }
                    else
                    {
                        Console.WriteLine("Unable to hook to device listener events");
                    }

                    _deviceListener = _device.DeviceListener;                                // Obtain a DeviceListener object for later use

                    Console.WriteLine("Device mute state: muted = " + _deviceListener.mute); // Obtain initial device microphone mute state
                }
                else
                {
                    Console.WriteLine("Unable to retrieve active device");
                }
            }
            catch (Exception)
            {
                Console.WriteLine("Unable to retrieve/hook to active device");
            }
        }
Exemplo n.º 3
0
        // detach from device events
        void DetachDevice()
        {
            if (m_activeDevice != null)
            {
                if (m_deviceComEvents != null)
                {
                    // commented out - not using these any more (see AttachDevice comment)
                    //// LC, new unregister the serial number events
                    //IDeviceCOMEventsExt_Event eex = m_deviceComEvents as IDeviceCOMEventsExt_Event;
                    //eex.HeadsetStateChanged -= eex_HeadsetStateChanged;
                    //IBaseCOMEvents_Event be = m_deviceComEvents as IBaseCOMEvents_Event;
                    //be.BaseEventReceived -= be_BaseEventReceived;

                    // unregister device event handlers
                    //m_deviceComEvents.onButtonPressed -= m_deviceComEvents_Handler; // not needed, instead rely on IDeviceListenerEvents.onHeadsetButtonPressed
                    m_deviceComEvents.onAudioStateChanged -= m_deviceComEvents_Handler;
                    m_deviceComEvents.onFlashButtonPressed -= m_deviceComEvents_Handler;
                    m_deviceComEvents.onMuteStateChanged -= m_deviceComEvents_Handler;
                    m_deviceComEvents.onSmartButtonPressed -= m_deviceComEvents_Handler;
                    //m_deviceComEvents.onTalkButtonPressed -= m_deviceComEvents_Handler; // not needed, instead rely on IDeviceListenerEvents.onHeadsetButtonPressed

                    //m_deviceComEvents.onDataReceived -= m_deviceComEvents_onDataReceived;  // commenting out this as it locks up on exit

                    Marshal.ReleaseComObject(m_deviceComEvents);
                    m_deviceComEvents = null;
                }
                if (m_deviceListenerEvents != null)
                {
                    // unregister device listener event handlers
                    m_deviceListenerEvents.onATDStateChanged -= m_deviceListenerEvents_Handler;
                    m_deviceListenerEvents.onBaseButtonPressed -= m_deviceListenerEvents_Handler;
                    m_deviceListenerEvents.onBaseStateChanged -= m_deviceListenerEvents_Handler;
                    m_deviceListenerEvents.onHeadsetButtonPressed -= m_deviceListenerEvents_Handler;
                    m_deviceListenerEvents.onHeadsetStateChanged -= m_deviceListenerEvents_HandlerMethods;

                    RegisterForProximity(false);
                    Marshal.ReleaseComObject(m_deviceListenerEvents);
                    m_deviceListenerEvents = null;
                }

                Marshal.ReleaseComObject(m_activeDevice);
                m_activeDevice = null;

                m_hostCommand = null;
                m_hostCommandExt = null;
                m_atdCommand = null;

                // LC Device was disconnected, clear down the GUI state...
                m_mobIncoming = false; // clear mobile call direction flag
                m_voipIncoming = false; // clear call direction flag
                OnNotOnCall(new NotOnCallArgs(0,""));
                OnNotOnMobileCall(EventArgs.Empty);

                OnSerialNumber(new SerialNumberArgs("", SerialNumberTypes.Base));
                OnSerialNumber(new SerialNumberArgs("", SerialNumberTypes.Headset));

                // LC Device was disconnected, remove capability data
                DeviceCapabilities = new SpokesDeviceCaps(false, false, false, false, false, false, false); // no device = no capabilities!
                m_devicename = "";
                m_baseserial = "";
                OnCapabilitiesChanged(EventArgs.Empty);

                m_lastdocked = false;
                //m_battlevEventCount = 0;

                // trigger user's event handler
                OnDetached(EventArgs.Empty);

                DebugPrint(MethodInfo.GetCurrentMethod().Name, "Spokes: DetachedEventHandler from device");
            }
            m_devicename = "";
            m_baseserial = "";
        }
Exemplo n.º 4
0
        // attach to device events
        private void AttachDevice()
        {
            try
            {
                m_activeDevice = m_comSession.GetActiveDevice();
            }
            catch (Exception e)
            {
                DebugPrint(MethodInfo.GetCurrentMethod().Name, "Spokes: Exception caught attaching to device: "+e.ToString());
                m_activeDevice = null;
            }
            if (m_activeDevice != null)
            {
                // LC assume minimum first set of device capabilities...
                DeviceCapabilities =
                    new SpokesDeviceCaps(false, false, false, false, false, false, false, false);
                OnCapabilitiesChanged(EventArgs.Empty);

                OnSerialNumber(new SerialNumberArgs("", SerialNumberTypes.Base));
                OnSerialNumber(new SerialNumberArgs("", SerialNumberTypes.Headset));

                // LC have seen case where ProductName was empty but InternalName was not...
                if (m_activeDevice.ProductName.Length > 0)
                {
                    m_devicename = m_activeDevice.ProductName;
                }
                else if (m_activeDevice.InternalName.Length > 0)
                {
                    m_devicename = m_activeDevice.InternalName;
                }
                else
                {
                    m_devicename = "Could not determine device name";
                }

                m_baseserial = m_activeDevice.SerialNumber;

                m_lastdocked = false;
                //m_battlevEventCount = 0;

                m_deviceComEvents = m_activeDevice as ICOMDeviceEvents_Event;
                if (m_deviceComEvents != null)
                {
                    // Attach to device events
                    m_deviceComEvents.onButtonPressed += m_deviceComEvents_Handler;  // not needed, instead rely on IDeviceListenerEvents.onHeadsetButtonPressed
                    //////m_deviceComEvents.onAudioStateChanged += m_deviceComEvents_Handler;
                    //////m_deviceComEvents.onFlashButtonPressed += m_deviceComEvents_Handler;
                    m_deviceComEvents.onMuteStateChanged += m_deviceComEvents_Handler;
                    //////m_deviceComEvents.onSmartButtonPressed += m_deviceComEvents_Handler;
                    //m_deviceComEvents.onTalkButtonPressed += m_deviceComEvents_Handler; // not needed, instead rely on IDeviceListenerEvents.onHeadsetButtonPressed

                    // LC 11-7-2013 TT: 23171   Cannot receive OLMP/Bladerunner responses from headset - need to expose Device.DataReceived event to COM
                    // Try adding onDataReceived event handler
                    m_deviceComEvents.onDataReceived += new ICOMDeviceEvents_onDataReceivedEventHandler(m_deviceComEvents_onDataReceived);

                    DebugPrint(MethodInfo.GetCurrentMethod().Name, "Spokes: AttachedEventHandler to device events");
                }
                else
                {
                    DebugPrint(MethodInfo.GetCurrentMethod().Name, "Spokes: Error: unable to attach to device events");
                    return;
                }

                //// if the ActiveDevice is a Calisto device, need additional initialization
                //// TODO: work out if this is needed in Spokes 3.0 - it's not currently exposed via COM!
                //if (m_activeDevice.HostCommand.IsSupported(FeatureType.FeatureType_DisplayDevice))
                //{
                //    InitDisplayDevice();
                //}

                m_deviceListenerEvents = m_activeDevice.DeviceListener as ICOMDeviceListenerEvents_Event;
                if (m_deviceListenerEvents != null)
                {
                    // Attach to device listener events
                    m_deviceListenerEvents.onATDStateChanged += m_deviceListenerEvents_Handler;
                    m_deviceListenerEvents.onBaseButtonPressed += m_deviceListenerEvents_Handler;
                    m_deviceListenerEvents.onBaseStateChanged += m_deviceListenerEvents_Handler;
                    m_deviceListenerEvents.onHeadsetButtonPressed += m_deviceListenerEvents_Handler;
                    m_deviceListenerEvents.onHeadsetStateChanged += m_deviceListenerEvents_HandlerMethods;
                }
                else
                {
                    DebugPrint(MethodInfo.GetCurrentMethod().Name, "Spokes: Error: unable to attach to device listener events");
                    return;
                }

                // The below call (now with exception catching) tries to register
                // for extended headsetstatechange and base events that were used
                // for reading serial numbers from device using "asyncronous" method.
                // Following discussion with Ramesh Feb 2013 the Spokes Wrapper
                // primarily tries to read serial numbers using the "syncronous"
                // method based on HeadsetStateChange/BaseStateChange serial number
                // events and GetSerialNumber_2 method. However, this has been left
                // in because GetSerialNumber_2 is not working! (At least this way the
                // base serial number is obtainable! LC 14th Mar 2013)
                RegisterForExtendedEvents();

                m_hostCommand = m_activeDevice.HostCommand;
                if (m_hostCommand == null) DebugPrint(MethodInfo.GetCurrentMethod().Name, "Spokes: Error: unable to obtain host command interface");
                m_atdCommand = m_activeDevice.HostCommand as ICOMATDCommand;
                if (m_atdCommand == null) DebugPrint(MethodInfo.GetCurrentMethod().Name, "Spokes: Error: unable to obtain atd command interface");
                m_hostCommandExt = m_activeDevice.HostCommand as ICOMHostCommandExt;
                if (m_hostCommandExt == null) DebugPrint(MethodInfo.GetCurrentMethod().Name, "Spokes: Error: unable to obtain host command ext interface");
                m_userPreference = m_sessionComManager.UserPreference;
                if (m_userPreference == null) DebugPrint(MethodInfo.GetCurrentMethod().Name, "Spokes: Error: unable to obtain user preference interface");
                m_advanceSettings = m_activeDevice.HostCommand as ICOMAdvanceSettings;
                if (m_advanceSettings == null) DebugPrint(MethodInfo.GetCurrentMethod().Name, "Spokes: Error: unable to obtain advanced settings interface");
                m_deviceSettings = m_activeDevice.HostCommand as ICOMDeviceSettings;
                if (m_deviceSettings == null) DebugPrint(MethodInfo.GetCurrentMethod().Name, "Spokes: Error: unable to obtain device settings interface");
                m_deviceListener = m_activeDevice.DeviceListener;
                if (m_deviceListener == null) DebugPrint(MethodInfo.GetCurrentMethod().Name, "Spokes: Error: unable to obtain device listener interface");

                m_deviceSettingsExt = m_activeDevice.HostCommand as ICOMDeviceSettingsExt;
                if (m_deviceSettingsExt == null) DebugPrint(MethodInfo.GetCurrentMethod().Name, "Spokes: Error: unable to obtain device settings ext interface");

                UpdateOtherDeviceCapabilities();

                // trigger user's event handler
                OnAttached(new AttachedArgs(m_activeDevice));

                OnSerialNumber(new SerialNumberArgs(m_baseserial, SerialNumberTypes.Base));

                // now poll for current state (proximity, mobile call status, donned status, mute status)
                GetInitialDeviceState();

                DebugPrint(MethodInfo.GetCurrentMethod().Name, "Spokes: AttachedEventHandler to device");
            }
        }