示例#1
0
        private SpokesDeviceCaps GetMyDeviceCapabilities()
        {
            SpokesDeviceCaps retval = new SpokesDeviceCaps();
            retval.HasProximity = false;
            retval.HasMobCallerId = false;
            retval.HasMobCallState = false;
            retval.HasDocking = false;
            retval.HasWearingSensor = false;
            retval.HasMultiline = false;
            retval.IsWireless = false;
            retval.ProductId = "";
            retval.HasQDConnector = false;
            string prodidstr, prodidstr2;

            if (m_activeDevice!=null && m_AllDeviceCapabilities.Count()>0)
            {
                prodidstr = string.Format("{0:X}", m_activeDevice.ProductId).ToUpper();
                prodidstr2 = string.Format("{0:X4}", m_activeDevice.ProductId).ToUpper();

                foreach (SpokesDeviceCaps caps in m_AllDeviceCapabilities)
                {
                    if (caps.ProductId.CompareTo(prodidstr)==0
                        || caps.ProductId.CompareTo(prodidstr2)==0)
                    {
                        // we got a match of our product!
                        DebugPrint(MethodInfo.GetCurrentMethod().Name, "INFO: Got a match of our Plantronics device in DeviceCapabilities.csv:");
                        DebugPrint(MethodInfo.GetCurrentMethod().Name, prodidstr);
                        retval = caps;
                        break;
                    }
                }
            }
            return retval;
        }
示例#2
0
        private void PreLoadAllDeviceCapabilities()
        {
            string line;

            SpokesDeviceCaps devicecaps;
            m_AllDeviceCapabilities = new List<SpokesDeviceCaps>();

            try
            {
                System.IO.StreamReader in_stream =
                   new System.IO.StreamReader("DeviceCapabilities.csv");

                while((line = in_stream.ReadLine()) != null)
                {
                        if (line.Length>0)
                        {
                            if (line.Substring(0,1).CompareTo("#")!=0 && line.Substring(0,1).CompareTo(",")!=0)
                            {
                                // not a comment line or empty line (with only commas)

                                devicecaps = new SpokesDeviceCaps();
                                string[] words = line.Split(',');

                                int i = 0;
                                string token = "";

                                foreach (string word in words)
                                {
                                    token = word.ToUpper();
                                    switch(i)
                                    {
                                    case 0:
                                        devicecaps.ProductId = word;
                                        break;
                                    case 1:
                                        // no action - this is the device name we don't need
                                        break;
                                    case 2:
                                        devicecaps.HasProximity = token.CompareTo("YES")==0 ? true : false;
                                        break;
                                    case 3:
                                        devicecaps.HasMobCallerId = token.CompareTo("YES") == 0 ? true : false;
                                        break;
                                    case 4:
                                        devicecaps.HasMobCallState = token.CompareTo("YES") == 0 ? true : false;
                                        break;
                                    case 5:
                                        devicecaps.HasDocking = token.CompareTo("YES") == 0 ? true : false;
                                        break;
                                    case 6:
                                        devicecaps.HasWearingSensor = token.CompareTo("YES") == 0 ? true : false;
                                        break;
                                    case 7:
                                        devicecaps.HasMultiline = token.CompareTo("YES") == 0 ? true : false;
                                        break;
                                    case 8:
                                        devicecaps.IsWireless = token.CompareTo("YES") == 0 ? true : false;
                                        break;
                                    case 9:
                                        devicecaps.HasQDConnector = token.CompareTo("YES") == 0 ? true : false;

                                        // now, add the devicecaps to our list:
                                        m_AllDeviceCapabilities.Add(devicecaps);

                                        break;
                                    }

                                    i++;
                                }

                                //DebugPrint(__FUNCTION__, "got some tokens");
                            }
                        }
                        //devicecaps
                }
                in_stream.Close();
            }
            catch(Exception e) {
                //std::cerr << "Exception opening/reading/closing file\n";
                DebugPrint(MethodInfo.GetCurrentMethod().Name, "Exception reading DeviceCapabilities.csv. Does this file exist in current working directory?");
            }
        }
示例#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 = "";
        }
示例#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");
            }
        }
示例#5
0
        /// <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;
        }
示例#6
0
        private SpokesDeviceCaps GetMyDeviceCapabilities()
        {
            SpokesDeviceCaps retval = new SpokesDeviceCaps();
            retval.ProductId="";
            string prodidstr;

            if (m_activeDevice!=null && m_AllDeviceCapabilities.Count()>0)
            {
                prodidstr = string.Format("{0:X}", m_activeDevice.ProductID).ToUpper();

                foreach (SpokesDeviceCaps caps in m_AllDeviceCapabilities)
                {
                    if (caps.ProductId.CompareTo(prodidstr)==0)
                    {
                        // we got a match of our product!
                        DebugPrint(MethodInfo.GetCurrentMethod().Name, "INFO: Got a match of our Plantronics device in DeviceCapabilities.csv:");
                        DebugPrint(MethodInfo.GetCurrentMethod().Name, prodidstr);
                        retval = caps;
                        break;
                    }
                }
            }
            return retval;
        }
示例#7
0
        // attach to device events
        private void AttachDevice()
        {
            try
            {
                m_activeDevice = m_comSession.ActiveDevice;
            }
            catch (Exception e)
            {
                DebugPrint(MethodInfo.GetCurrentMethod().Name, "Spokes: Exception caught attaching to device: "+e.ToString());
            }
            if (m_activeDevice != null)
            {
                // LC assume minimum first set of device capabilities...
                DeviceCapabilities =
                    new SpokesDeviceCaps(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_lastdocked = false;
                m_battlevEventCount = 0;

                m_deviceComEvents = m_activeDevice.DeviceEvents as IDeviceCOMEvents_Event;
                if (m_deviceComEvents != null)
                {
                    // Attach to device events
                    m_deviceComEvents.ButtonPressed += m_deviceComEvents_Handler;
                    m_deviceComEvents.AudioStateChanged += m_deviceComEvents_Handler;
                    //m_deviceComEvents.FlashPressed += m_deviceComEvents_Handler;
                    m_deviceComEvents.MuteStateChanged += m_deviceComEvents_Handler;
                    //m_deviceComEvents.SmartPressed += m_deviceComEvents_Handler;
                    //m_deviceComEvents.TalkPressed += m_deviceComEvents_Handler;
                    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
                if (m_activeDevice.HostCommand.IsSupported(FeatureType.FeatureType_DisplayDevice))
                {
                    InitDisplayDevice();
                }

                m_deviceListenerEvents = m_activeDevice.DeviceListener as IDeviceListenerCOMEvents_Event;
                if (m_deviceListenerEvents != null)
                {
                    // Attach to device listener events
                    m_deviceListenerEvents.ATDStateChanged += m_deviceListenerEvents_Handler;
                    m_deviceListenerEvents.BaseButtonPressed += m_deviceListenerEvents_Handler;
                    m_deviceListenerEvents.BaseStateChanged += m_deviceListenerEvents_Handler;
                    m_deviceListenerEvents.HeadsetButtonPressed += m_deviceListenerEvents_Handler;
                    m_deviceListenerEvents.HeadsetStateChanged += 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 IATDCommand;
                if (m_atdCommand == null) DebugPrint(MethodInfo.GetCurrentMethod().Name, "Spokes: Error: unable to obtain atd command interface");
                m_hostCommandExt = m_activeDevice.HostCommand as IHostCommandExt;
                if (m_hostCommandExt == null) DebugPrint(MethodInfo.GetCurrentMethod().Name, "Spokes: Error: unable to obtain host command ext interface");

                UpdateOtherDeviceCapabilities();

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

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

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