Ejemplo n.º 1
0
        /// <summary> Starts connection to the WeDo Hubs. </summary>
        /// <returns> If the method completed with success the returning value is
        ///   <see cref="wclErrors.WCL_E_SUCCESS" />. If the method failed the returning value is
        ///   one of the Bluetooth Framework error code. </returns>
        /// <remarks> The method starts searching for WeDo Hubs and to connect to each found. Once the Hub found
        ///   the <c>OnHubFound</c> event fires. An application may accept connection to this Hub by setting
        ///   the <c>Connect</c> parameter to <c>true</c>. </remarks>
        public Int32 Start()
        {
            if (FRadio != null)
            {
                return(wclConnectionErrors.WCL_E_CONNECTION_ACTIVE);
            }

            Int32 Res = FManager.Open();

            if (Res == wclErrors.WCL_E_SUCCESS)
            {
                Res = FManager.GetLeRadio(out FRadio);
                if (Res == wclErrors.WCL_E_SUCCESS)
                {
                    // Try to start watching for HUBs.
                    Res = FWatcher.Start(FRadio);

                    // If something went wrong we must clear the working radio objecy.
                    if (Res != wclErrors.WCL_E_SUCCESS)
                    {
                        FRadio = null;
                    }
                }

                // If something went wrong we must close Bluetooth Manager
                if (Res != wclErrors.WCL_E_SUCCESS)
                {
                    FManager.Close();
                }
            }
            return(Res);
        }
Ejemplo n.º 2
0
        /// <summary> Starts connection to the WeDo Hubs. </summary>
        /// <returns> If the method completed with success the returning value is
        ///   <see cref="wclErrors.WCL_E_SUCCESS" />. If the method failed the returning value is
        ///   one of the Bluetooth Framework error code. </returns>
        /// <remarks> The method starts searching for WeDo Hubs and to connect to each found. Once the Hub found
        ///   the <c>OnHubFound</c> event fires. An application may accept connection to this Hub by setting
        ///   the <c>Connect</c> parameter to <c>true</c>. </remarks>
        public Int32 Start()
        {
            if (FRadio != null)
            {
                return(wclConnectionErrors.WCL_E_CONNECTION_ACTIVE);
            }

            Int32 Res = FManager.Open();

            if (Res == wclErrors.WCL_E_SUCCESS)
            {
                if (FManager.Count == 0)
                {
                    Res = wclBluetoothErrors.WCL_E_BLUETOOTH_API_NOT_FOUND;
                }
                else
                {
                    // Look for first available radio.
                    for (int i = 0; i < FManager.Count; i++)
                    {
                        if (FManager[i].Available)
                        {
                            FRadio = FManager[i];
                            break;
                        }
                    }

                    if (FRadio == null)
                    {
                        Res = wclBluetoothErrors.WCL_E_BLUETOOTH_RADIO_UNAVAILABLE;
                    }
                    else
                    {
                        // Try to start watching for HUBs.
                        Res = FWatcher.Start(FRadio);

                        // If something went wrong we must clear the working radio objecy.
                        if (Res != wclErrors.WCL_E_SUCCESS)
                        {
                            FRadio = null;
                        }
                    }
                }

                // If something went wrong we must close Bluetooth Manager
                if (Res != wclErrors.WCL_E_SUCCESS)
                {
                    FManager.Close();
                }
            }
            return(Res);
        }