예제 #1
0
파일: main.cs 프로젝트: btframework/WeDo
        private void BtConnect_Click(Object Sender, EventArgs e)
        {
            // The very first thing we have to do is to open Bluetooth Manager.
            // That initializes the underlying drivers and allows us to work with Bluetooth.

            // Always check result!
            Int32 Res = FManager.Open();

            if (Res != wclErrors.WCL_E_SUCCESS)
            {
                // It should never happen but if it does notify user.
                MessageBox.Show("Unable to open Bluetooth Manager: 0x" + Res.ToString("X8"));
            }
            else
            {
                // Assume that no one Bluetooth Radio available.
                wclBluetoothRadio Radio = null;
                Res = FManager.GetLeRadio(out Radio);
                if (Res != wclErrors.WCL_E_SUCCESS)
                {
                    // If not, let user know that he has no Bluetooth.
                    MessageBox.Show("No available Bluetooth Radio found");
                }
                else
                {
                    // If found, try to start discovering.
                    Res = FWatcher.Start(Radio);
                    if (Res != wclErrors.WCL_E_SUCCESS)
                    {
                        // It is something wrong with discovering starting. Notify user about the error.
                        MessageBox.Show("Unable to start discovering: 0x" + Res.ToString("X8"));
                    }
                    else
                    {
                        btConnect.Enabled    = false;
                        btDisconnect.Enabled = true;
                        laStatus.Text        = "Searching...";
                    }
                }

                // Again, check the found Radio.
                if (Res != wclErrors.WCL_E_SUCCESS)
                {
                    // And if it is null (not found or discovering was not started
                    // close the Bluetooth Manager to release all the allocated resources.
                    FManager.Close();
                    // Also clean up found Radio variable so we can check it later.
                    Radio = null;
                }
            }
        }
예제 #2
0
        /**
         * <summary>When the Simple_Form loads</summary>
         * <param name="sender">Object on which the change happened</param>
         * <param name="e">Additional information about the event</param>
         */
        private void Simple_Form_Load(object sender, EventArgs e)
        {
            lineTracker = new LineTracker(this);
            Manager     = new wclBluetoothManager();
            Watcher     = new wclWeDoWatcher();
            listBox1.Items.Add("Please connect one of the hubs.");

            Watcher.OnHubFound += Watcher_OnHubFound;

            int res = Manager.Open();

            if (res != wclErrors.WCL_E_SUCCESS)
            {
                MessageBox.Show("Error opening the Manager.");
            }
            else
            {
                wclBluetoothRadio radio = null;
                for (int i = 0; i < Manager.Count; i++)
                {
                    if (Manager[i].Available)
                    {
                        radio = Manager[i];
                        break;
                    }
                }
                if (radio != null)
                {
                    res = Watcher.Start(radio);
                    if (res != wclErrors.WCL_E_SUCCESS)
                    {
                        MessageBox.Show("Can't start watching.");
                    }
                }
            }
        }
예제 #3
0
        private void BtStart_Click(Object Sender, EventArgs e)
        {
            // The very first thing we have to do is to open Bluetooth Manager.
            // That initializes the underlying drivers and allows us to work with Bluetooth.

            // Always check result!
            Int32 Res = FManager.Open();

            if (Res != wclErrors.WCL_E_SUCCESS)
            {
                // It should never happen but if it does notify user.
                MessageBox.Show("Unable to open Bluetooth Manager: 0x" + Res.ToString("X8"));
            }
            else
            {
                // Assume that no one Bluetooth Radio available.
                wclBluetoothRadio Radio = null;

                // Check that at least one Bluetooth Radio exists (or at least Bluetooth drivers installed).
                if (FManager.Count == 0)
                {
                    // No one, even drivers?
                    MessageBox.Show("No Bluetooth Hardware installed");
                }
                else
                {
                    // Ok, at least one Bluetooth Radio module should be available.
                    for (Int32 i = 0; i < FManager.Count; i++)
                    {
                        // Check if current Radio module is available (plugged in and turned ON).
                        if (FManager[i].Available)
                        {
                            // Looks like we have Bluetooth on this PC!
                            Radio = FManager[i];
                            // Terminate the loop.
                            break;
                        }
                    }

                    // Check that we found the Bluetooth Radio module.
                    if (Radio == null)
                    {
                        // If not, let user know that he has no Bluetooth.
                        MessageBox.Show("No available Bluetooth Radio found");
                    }
                    else
                    {
                        // If found, try to start discovering.
                        Res = FWatcher.Start(Radio);
                        if (Res != wclErrors.WCL_E_SUCCESS)
                        {
                            // It is something wrong with discovering starting. Notify user about the error.
                            MessageBox.Show("Unable to start discovering: 0x" + Res.ToString("X8"));
                            // Also clean up found Radio variable so we can check it later.
                            Radio = null;
                        }
                    }
                }

                // Again, check the found Radio.
                if (Radio == null)
                {
                    // And if it is null (not found or discovering was not started
                    // close the Bluetooth Manager to release all the allocated resources.
                    FManager.Close();
                }
            }
        }