Пример #1
0
        /// <summary>
        /// This method is called when the discovery process is completed.
        /// It attempts to create a Bluetooth connection the specified device
        /// </summary>
        private static void DiscoverDevicesComplete(object sender, DiscoverDevicesEventArgs e)
        {
            // Get a list of previously paired devices
            List <BluetoothDeviceInfo> devices = e.Devices.OfType <BluetoothDeviceInfo>().ToList();
            BluetoothDeviceInfo        device  = devices.Find(item => item.DeviceName.Equals("Shimmer3-" + SHIMMER_ID));

            if (device == null)
            {
                //Console.WriteLine("Shimmer3-" + SHIMMER_ID + " could not be discovered");
                connecting = false;
            }
            else
            {
                // Check if device can be paired
                if (BluetoothSecurity.PairRequest(device.DeviceAddress, SHIMMER_PIN))
                {
                    // set pin of device to connect with
                    localClient.SetPin(SHIMMER_PIN);
                    // async connection method
                    localClient.BeginConnect(device.DeviceAddress, BluetoothService.SerialPort, new AsyncCallback(Connected_Callback), device);
                }
                else
                {
                    //Console.WriteLine("Shimmer3-" + SHIMMER_ID + " could not be paired");
                    connecting = false;
                }
            }
        }
Пример #2
0
 /// <summary>
 /// The callback for when asynchronous device discovery completes.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="discoverDevicesEventArgs">The event arguments.</param>
 private void ComponentOnDiscoverDevicesComplete(object sender, DiscoverDevicesEventArgs discoverDevicesEventArgs)
 {
     foreach (var discoveredDevice in discoverDevicesEventArgs.Devices)
     {
         LogMessage($"Discovered > {discoveredDevice.DeviceName} [{discoveredDevice.DeviceAddress}]: {(discoveredDevice.Authenticated ? "Authenticated, " : "")}{(discoveredDevice.Connected ? "Connected, " : "")}{(discoveredDevice.Remembered ? "Remembered, " : "")}{discoveredDevice.ClassOfDevice.Device} ({discoveredDevice.ClassOfDevice.MajorDevice}), {discoveredDevice.Rssi}");
     }
 }
Пример #3
0
        private void Bc_DiscoverDevicesComplete(object sender, DiscoverDevicesEventArgs e)
        {
            Console.WriteLine("Devices discovered");

            e.Devices.ToList().ForEach(d => DeviceList.Add(d));
            DeviceDiscoveryTask.SetResult(true);
        }
Пример #4
0
        void bco_DiscoverDevicesProgress(object sender, DiscoverDevicesEventArgs e)
        {
            Debug.Assert(e.Error == null && !e.Cancelled, "Never raised by BtCompnt!");
            var dlgt = new EventHandler <DiscoverDevicesEventArgs>(UpdateProgressChanged);

            lvDevices.BeginInvoke(dlgt, this, e);
        }
Пример #5
0
 private void component_DiscoverDevicesProgress(object sender, DiscoverDevicesEventArgs e)
 {
     for (int i = 0; i < e.Devices.Length; i++)
     {
         this.DiscoveredDeviceList.Add(e.Devices[i]);
     }
 }
Пример #6
0
 // Evenement "progression de la découverte", est appelé lorsque des périphériques bluetooth sont découverts
 private void DiscoverProgress(object sender, DiscoverDevicesEventArgs e)
 {
     foreach (BluetoothDeviceInfo b in e.Devices)
     {
         NXTDevice device = new NXTDevice(b);
         listBox1.Items.Add(device);
     }
 }
Пример #7
0
        // Lorsque des périphériques bluetooth sont découverts
        private void DiscoveryProgress(Object sender, DiscoverDevicesEventArgs e)
        {
            foreach (BluetoothDeviceInfo b in e.Devices)
            {
                discoveredDevices.Add(b);
            }

            deviceFound.Invoke(this, e);
        }
Пример #8
0
        /// <summary>
        /// End is an event handler that is triggered when the search stops.
        /// </summary>
        /// <param name="sender">(Unused)</param>
        /// <param name="args">(Unused)</param>
        private void End(object sender, DiscoverDevicesEventArgs args)
        {
            for (int i = 0; i < observers.Count; i++)
            {
                ((IDiscovererObserver)observers[i]).onDiscoveryFinished();
            }

            isSearching = false;
        }
 static void onDiscoverDevicesProgress(object sender, DiscoverDevicesEventArgs e)
 {
     Console.WriteLine("Device discovery in progress");
     foreach (var device in e.Devices)
     {
         Console.WriteLine(device.DeviceName);
     }
     Console.WriteLine();
 }
Пример #10
0
 void UpdateProgressChanged(object sender, DiscoverDevicesEventArgs e)
 {
     if (_closed)
     {
         return;
     }
     BluetoothDeviceInfo[] newDevices = e.Devices;
     newDevices = DoFiltering(newDevices);
     AppendDevices(newDevices);
 }
Пример #11
0
        void bco_DiscoverDevicesComplete(object sender, DiscoverDevicesEventArgs e)
        {
            var dlgt = new EventHandler <DiscoverDevicesEventArgs>(UpdateCompleted);

            lvDevices.BeginInvoke(dlgt, this, e);
            //
            var bco = (BluetoothComponent)e.UserState;

            bco.Dispose();
        }
Пример #12
0
        private void Scan_Complete(object sender, DiscoverDevicesEventArgs e)
        {
            Console.WriteLine("Devices discovered: " + e.Devices);

            /*
             * _window.pb.Visibility = Visibility.Hidden;
             * _window.device_list.ItemsSource = devicesWrapper;
             * _window.listen_btn.Visibility = Visibility.Visible;
             * _window.btn_find.Visibility = Visibility.Visible;
             */
        }
Пример #13
0
 private void bluetoothComponent_DiscoverDevicesProgress(object sender, DiscoverDevicesEventArgs e)
 {
     foreach (BluetoothDeviceInfo device in e.Devices)
     {
         Debug.WriteLine(device.DeviceName + " is a " + device.ClassOfDevice.MajorDevice.ToString());
         if (device.DeviceName.Contains("linepod-photobooth") && !alreadyPaired) //osboxes vs raspberry
         {
             this.device = device;
         }
     }
 }
Пример #14
0
        private void component_DiscoverDevicesProgress(object sender, DiscoverDevicesEventArgs e)
        {
            // log and save all found devices
            for (int i = 0; i < e.Devices.Length; i++)
            {
                devices.Add(e.Devices[i]);

                string t = e.Devices[i].DeviceName + " (" + e.Devices[i].DeviceAddress + "): ";
                t += e.Devices[i].Remembered ? "znane" : "nieznane";
                PickDevice.Items.Add(t);
            }
        }
Пример #15
0
        private static void component_DiscoverDevicesProgress(object sender, DiscoverDevicesEventArgs e)
        {
            e.Devices.ToList().ForEach(dev =>
                                       Console.WriteLine(
                                           dev.DeviceName +
                                           " (" + dev.DeviceAddress +
                                           "): Device is " +
                                           (dev.Remembered ? "known." : "unknown.")
                                           )
                                       );

            deviceList.AddRange(e.Devices);
        }
Пример #16
0
        private void DiscoverDevicesFinish(object sender, DiscoverDevicesEventArgs e)
        {
            bt = new List <BluetoothDeviceInfo>();
            foreach (BluetoothDeviceInfo dev in e.Devices)
            {
                bt.Add(dev);
            }

            dataGridView1.DataSource = null;
            dataGridView1.Update();
            dataGridView1.DataSource = e.Devices;
            dataGridView1.Update();
        }
Пример #17
0
 /// <summary>
 /// Lists all discovered Bluetooth devices
 /// </summary>
 private static void DiscoverDevices(object sender, DiscoverDevicesEventArgs e)
 {
     for (int i = 0; i < e.Devices.Length; i++)
     {
         if (e.Devices[i].Remembered)
         {
             //Console.WriteLine(e.Devices[i].DeviceName + " (" + e.Devices[i].DeviceAddress + "): Device is known");
         }
         else
         {
             //Console.WriteLine(e.Devices[i].DeviceName + " (" + e.Devices[i].DeviceAddress + "): Device is unknown");
         }
     }
 }
Пример #18
0
 private void component_DiscoverDevicesProgress(object sender, DiscoverDevicesEventArgs e)
 {
     for (int i = 0; i < e.Devices.Length; i++)
     {
         if (e.Devices[i].Remembered)
         {
             Console.WriteLine(e.Devices[i].DeviceName + " (" + e.Devices[i].DeviceAddress + "): Device is known");
         }
         else
         {
             Console.WriteLine(e.Devices[i].DeviceName + " (" + e.Devices[i].DeviceAddress + "): Device is unknown");
         }
         deviceList.Add(e.Devices[i]);
     }
 }
Пример #19
0
 // метод в конце поиска
 private void BluetoothEndDescovery(object sender, DiscoverDevicesEventArgs e)
 {
     // если не найдено щапускаем форму сравнения паролей
     if (compare == 0)
     {
         // если устройства нет рядом просим ввести пароль
         NotFoundCheckingPassword password = new NotFoundCheckingPassword(cod);
         password.ShowDialog();
         // проверка верности пароля
         if (password.Pasbool)
         {
             Redeem();
         }
     }
 }
Пример #20
0
 private static void ComponentDiscoverDevicesProgress(object sender, DiscoverDevicesEventArgs e)
 {
     // log and save all found devices
     for (int i = 0; i < e.Devices.Length; i++)
     {
         if (e.Devices[i].Remembered)
         {
             //Print(e.Devices[i].DeviceName + " (" + e.Devices[i].DeviceAddress + "): Device is known");
         }
         else
         {
             //Print(e.Devices[i].DeviceName + " (" + e.Devices[i].DeviceAddress + "): Device is unknown");
         }
         deviceList.Add(e.Devices[i]);
     }
 }
 private void component_DiscoverDevicesProgress(object sender, DiscoverDevicesEventArgs e)
 {
     // log and save all found devices
       for (int i = 0; i < e.Devices.Length; i++)
       {
     if (e.Devices[i].Remembered)
     {
       MessageBox.Show(e.Devices[i].DeviceName + " (" + e.Devices[i].DeviceAddress + "): Device is known");
     }
     else
     {
       MessageBox.Show(e.Devices[i].DeviceName + " (" + e.Devices[i].DeviceAddress + "): Device is unknown");
     }
     this.deviceList.Add(e.Devices[i]);
       }
 }
Пример #22
0
 private void LocalComponent_DiscoverDevicesProgress(object sender, DiscoverDevicesEventArgs e)
 {
     foreach (var dev in e.Devices)
     {
         DeviceDetails dd = new DeviceDetails
         {
             Name   = dev.DeviceName,
             Adress = dev.DeviceAddress.ToString()
         };
         App.Current.Dispatcher.Invoke((Action) delegate
         {
             observableCollection.Add(dd);
             latestsearch.Add(dev);
         });
     }
 }
Пример #23
0
 private void component_DiscoverDevicesProgress(object sender, DiscoverDevicesEventArgs e)
 {
     // log and save all found devices
     for (int i = 0; i < e.Devices.Length; i++)
     {
         if (e.Devices[i].Remembered)
         {
             MessageBox.Show(e.Devices[i].DeviceName + " (" + e.Devices[i].DeviceAddress + "): Device is known");
         }
         else
         {
             MessageBox.Show(e.Devices[i].DeviceName + " (" + e.Devices[i].DeviceAddress + "): Device is unknown");
         }
         this.deviceList.Add(e.Devices[i]);
     }
 }
Пример #24
0
        /// <summary>
        /// Progress is an event handler that is triggered when a device is found.
        /// </summary>
        /// <param name="sender">(Unused)</param>
        /// <param name="args">Holds the device found.</param>
        private void Progress(object sender, DiscoverDevicesEventArgs args)
        {
            for (int i = 0; i < args.Devices.Length; i++)
            {
                Device nch = new Device(args.Devices[i]);
                if (!nchs.Contains <Device>(nch) && nch.DeviceName.ToLower().Contains("nch"))
                {
                    print("Adding " + nch.DeviceName);
                    nchs[index] = nch;
                    index++;

                    foreach (IDiscovererObserver observer in observers)
                    {
                        observer.OnDeviceFound(nch);
                    }
                }
            }
        }
Пример #25
0
        public void Scan(object sender, DiscoverDevicesEventArgs e)
        {
            // log and save all found devices

            for (int i = 0; i < e.Devices.Length; i++)
            {
                this.deviceList.Add(e.Devices[i]);

                if (e.Devices[i].Remembered)
                {
                    Console.WriteLine(e.Devices[i].DeviceName + " (" + e.Devices[i].DeviceAddress + "): Device is known");
                }
                else
                {
                    devicesWrapper.Add(new Device(e.Devices[i]));
                    Console.WriteLine(e.Devices[i].DeviceName + " (" + e.Devices[i].DeviceAddress + "): Device is unknown");
                }
            }
        }
Пример #26
0
 // метод вызываемый при нахождении очередного устройства и проверяющий его совпадаение с выбранным при шифровке файла
 private void BluetoothDescovery(object sender, DiscoverDevicesEventArgs e)
 {
     // проверка найден ли уже
     if (compare == 0)
     {
         if (e.Devices != null)
         {
             // сравниваем совпадает ли адрес того, что поблизости с указаным в клчевом файле
             foreach (var item in e.Devices)
             {
                 if (item.DeviceAddress.ToString() == deviceadress)
                 {
                     compare = 1;
                     Redeem();
                 }
             }
         }
     }
 }
Пример #27
0
 //Called after the discovery process is completed
 void BluetoothComponent_DiscoverDevicesComplete(object sender, DiscoverDevicesEventArgs e)
 {
     ScanStatus.BeginAnimation(OpacityProperty, null);
     if (devicesList == null)
     {
         ScanStatus.Text = "No devices found";
     }
     else
     {
         ScanStatus.Text = "Select a device below to connect";
         foreach (BluetoothDeviceInfo device in devicesList)
         {
             foundItems.Add(new DeviceItem()
             {
                 Title = device.DeviceName, Level = 100, Source = Source(device.ClassOfDevice.MajorDevice.ToString())
             });
         }
     }
 }
Пример #28
0
        private void UpdateCompleted(object sender, DiscoverDevicesEventArgs e)
        {
            if (_closed)
            {
                return;
            }
            // See if the background worker method failed
            if (e.Error != null)
            {
#if DEBUG
                MessageBox.Show("e.Error is set, must have been an exception!");
#endif
                System.Diagnostics.Debug.Assert(e.Error as PlatformNotSupportedException != null,
                                                "When devices=null, expect PlatformNotSupportedException.");
                System.Diagnostics.Debug.Assert(e.Error.InnerException as SocketException != null,
                                                "When devices=null, expect innerException SocketException.");
                ListViewItem lvi = new ListViewItem("Failed: " + e.Error);
                lvi.ImageIndex = -1;
                lvDevices.Items.Add(lvi);
            }
            else
            {
                BluetoothDeviceInfo[] newDevices = e.Devices;
                if (newDevices == null)
                {
#if DEBUG
                    MessageBox.Show("devices is null, must have been an exception!");
#endif
                }
                else
                {
                    newDevices = DoFiltering(newDevices);
                    AppendDevices(newDevices);
                }
            }

            mnuAgain.Enabled = true;

            lvDevices.Focus();

            Cursor.Current = Cursors.Default;
        }
Пример #29
0
        private void component_DiscoverDevicesProgress(object sender, DiscoverDevicesEventArgs e)
        {
            // log and save all found devices
            for (int i = 0; i < e.Devices.Length; i++)
            {
                if (e.Devices[i].Remembered)
                {
                    Console.WriteLine(e.Devices[i].DeviceName + " (" + e.Devices[i].DeviceAddress + "): Device is known");
                }
                else
                {
                    Console.WriteLine(e.Devices[i].DeviceName + " (" + e.Devices[i].DeviceAddress + "): Device is unknown");
                }

                if (OnSearchDevice != null)
                {
                    OnSearchDevice(e.Devices[i]);
                }
            }
        }
        static void onDiscoverDevicesComplete(object sender, DiscoverDevicesEventArgs e)
        {
            Console.WriteLine("Device discovery complete");
            foreach (var device in e.Devices)
            {
                Console.WriteLine(device.DeviceName);
            }
            Console.WriteLine();

            _device = e.Devices.ToList().Where(p => p.DeviceName == DEVICE_NAME).FirstOrDefault();

            if (_device != null)
            {
                Console.WriteLine("Selected {0} device with address {1}", _device.DeviceName, _device.DeviceAddress);

                using (BluetoothClient client = new BluetoothClient())
                {
                    client.Connect(new BluetoothEndPoint(_device.DeviceAddress, BluetoothService.SerialPort));
                    Stream peerStream = client.GetStream();

                    for (int i = 0; i < 100; i++)
                    {
                        byte[] wb = Encoding.ASCII.GetBytes(string.Format("{0:X2} : This is a test : {1}{2}", i, DateTime.Now.ToString("o"), Environment.NewLine));
                        peerStream.Write(wb, 0, wb.Length);
                    }

                    byte [] buf        = new byte[1024];
                    int     readLength = peerStream.Read(buf, 0, buf.Length);
                    if (readLength > 0)
                    {
                        Console.WriteLine("Received {0} bytes", readLength);
                    }
                    else
                    {
                        Console.WriteLine("Connection is closed");
                    }
                }
            }
        }
Пример #31
0
        /// <summary>
        /// Callback on a completed discover operation
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void discoverComplete(object sender, DiscoverDevicesEventArgs e)
        {
            BluetoothDeviceInfo[] devices;

            try {
                devices = e.Devices;
            } catch (Exception ex) {
                // I was getting a reflection invocation exception. WTF!!

                BluetoothComponent bt = (BluetoothComponent)sender;
                // bt.DiscoverDevicesComplete += new EventHandler<DiscoverDevicesEventArgs>(discoverComplete);
                bt.DiscoverDevicesAsync(100, true, true, true, true, null);

                return;
            }

            foreach (MenuItem menu in playersItem.MenuItems) {
                if (menu == null)
                    continue;   // WTF?

                if (menu.Text.EndsWith("(nearby)"))
                    menu.Text = menu.Text.Replace("(nearby)", "");
            }

            try {
                foreach (BluetoothDeviceInfo device in devices) {
                    string addr = device.DeviceAddress.ToString("C").Replace(":", "-").ToLower();

                    foreach (MenuItem menu in playersItem.MenuItems) {
                        if (menu == null)
                            continue;   // WTF?

                        NetService service = (NetService)menu.Tag;
                        if (service == null)
                            continue;   // WTF
                        if (service.TXTRecordData != null) {
                            IDictionary dict = NetService.DictionaryFromTXTRecordData(service.TXTRecordData);

                            if (dict != null) {
                                foreach (DictionaryEntry kvp in dict) {
                                    String key = (String)kvp.Key;

                                    key = key.ToUpper();
                                    if (key.Equals("BLUETOOTH")) {
                                        byte[] value = (byte[])kvp.Value;
                                        try {
                                            if (Encoding.UTF8.GetString(value).ToLower().Equals(addr)) {
                                                menu.Text = menu.Text + "(nearby)";
                                            }
                                        } catch {
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }

                BluetoothComponent bt = (BluetoothComponent)sender;
                // bt.DiscoverDevicesComplete += new EventHandler<DiscoverDevicesEventArgs>(discoverComplete);
                bt.DiscoverDevicesAsync(100, true, true, true, true, null);
            } catch {
            }
        }
        private void HandleDiscoDevicesProgress(object sender, DiscoverDevicesEventArgs e)
        {
            foreach (BluetoothDeviceInfo device in e.Devices) {

                object[] findTheseVals = new object[1];
                findTheseVals[0] = device.DeviceAddress.ToString();
                DataRow foundRow = dataTable.Rows.Find(findTheseVals);

                if (foundRow == null) {
                    dataTable.Rows.Add(device.DeviceName, "", device.DeviceAddress.ToString());
                }
            }
        }
        /*private void AddNode(XmlNode inXmlNode, TreeNode inTreeNode) {
            XmlNode xNode;
            TreeNode tNode;
            XmlNodeList nodeList;
            int i;

            // Loop through the XML nodes until the leaf is reached.
            // Add the nodes to the TreeView during the looping process.
            if (inXmlNode.HasChildNodes) {
                nodeList = inXmlNode.ChildNodes;
                for (i = 0; i <= nodeList.Count - 1; i++) {
                    xNode = inXmlNode.ChildNodes[i];
                    inTreeNode.Nodes.Add(new TreeNode(xNode.Name));
                    tNode = inTreeNode.Nodes[i];
                    AddNode(xNode, tNode);
                }
            } else {
                // Here you need to pull the data from the XmlNode based on the
                // type of node, whether attribute values are required, and so forth.
                inTreeNode.Text = (inXmlNode.OuterXml).Trim();
            }
        }*/
        private void HandleDiscoDevicesComplete(object sender, DiscoverDevicesEventArgs e)
        {
            if (e.Cancelled) {
                Console.WriteLine("DiscoDevicesAsync cancelled.");
            } else if (e.Error != null) {
                Console.WriteLine("DiscoDevicesAsync error: {0}.", e.Error.Message);
            } else {
                Console.WriteLine("DiscoDevicesAsync complete found {0} devices.", e.Devices.Length);
                sendPhoneInfo();
            }
            btnSearch.IsEnabled = true;
            btnClear.IsEnabled = true;
        }
 private void component_DiscoverDevicesComplete(object sender, DiscoverDevicesEventArgs e)
 {
     Console.WriteLine("done");
     isScanDone = true;
     List<String> targetList = robots.ConvertAll(x => x.DeviceName);
     if (onRobotsDiscoverDone_Event != null)
         onRobotsDiscoverDone_Event.Invoke(targetList);
 }
 private void component_DiscoverDevicesProgress(object sender, DiscoverDevicesEventArgs e)
 {
     // log and save all found devices
     for (int i = 0; i < e.Devices.Length; i++)
     {
         robots.Add(e.Devices[i]);
         if (onRobotDiscovered_Event != null)
             onRobotDiscovered_Event.Invoke(e.Devices[i].DeviceName);
     }
 }
 private void component_DiscoverDevicesComplete(object sender, DiscoverDevicesEventArgs e)
 {
     // log some stuff
       pairing();
 }
Пример #37
0
 private void component_DiscoverDevicesComplete(object sender, DiscoverDevicesEventArgs e)
 {
     IsSearching = false;
 }
Пример #38
0
        void bt_DiscoverDevicesComplete(object sender, DiscoverDevicesEventArgs e)
        {
            _bluetoothDeviceList.Clear();

            foreach (BluetoothDeviceInfo device in e.Devices)
            {
                _bluetoothDeviceList.Add(device);
            }
            BlueTimer.Start();
        }