private void Scanner()
 {
   
     updateUI("Starting Scan...");
     BluetoothClient client = new BluetoothClient();
     devices = client.DiscoverDevicesInRange();
     updateUI("Scan complete");
     updateUI(devices.Length.ToString() + " devices discovered");
     foreach(BluetoothDeviceInfo d in devices)
     {
         items.Add(d.DeviceName);
     }
     updateDeviceList();
 }
Beispiel #2
0
        public static void FindNXTDevices(object sender, DoWorkEventArgs eventArgs)
        {
            while (continueDeviceDiscovery)
            {
                if (!availableRobots.ContainsKey("USB")) // If a usb was not connected before test it now
                {
                    NXT usbNXT = new NXT("USB", new NXTUsbConnection());
                    if (usbNXT.nxtConn.IsConnected)
                    {
                        availableRobots.Add("USB", usbNXT);
                        OnDeviceAdded(usbNXT);
                    }
                }

                var btClient = new BluetoothClient();
                List<BluetoothClient> btRobots = new List<BluetoothClient>();
                btClient.InquiryLength = new TimeSpan(0, 0, 4);
                BluetoothDeviceInfo[] btDevices = btClient.DiscoverDevicesInRange();
                foreach (BluetoothDeviceInfo btDevice in btDevices)
                {
                    try
                    {
                        // The property InstalledServices only lists services for devices that have been paired with
                        // the computer already (rather than requesting it from the device). This is fine in our
                        // scenario since you cant get a service list off the devices unless it is already paired.
                        if (btDevice.InstalledServices.Contains(NXT32FeetBT.NXT_BT_SERVICE))
                        {
                            String nxtIdentifier = btDevice.DeviceAddress.ToString();
                            if (!availableRobots.ContainsKey(nxtIdentifier))
                            {
                                NXT foundNXT = new NXT(nxtIdentifier, new NXT32FeetBT(btDevice.DeviceAddress));
                                availableRobots.Add(nxtIdentifier, foundNXT);
                                OnDeviceAdded(foundNXT);
                            }
                            else
                            {
                                if (!availableRobots[nxtIdentifier].connected)
                                {
                                    availableRobots[nxtIdentifier].Reconnect();
                                }
                            }
                        }
                    }
                    catch (SocketException e) { } // Socket exception occurs if the device is not an nxt
                }

                // Check if any previously found devices were lost
                var btAddresses = from btDevice in btDevices
                                  select btDevice.DeviceAddress.ToString();
                foreach (NXT nxt in AvailableRobots.Values)
                {
                    if (!btAddresses.Contains(nxt.uniqueID))
                    {
                        nxt.connected = false;
                        nxt.OnDeviceDisconnected();
                    }
                }

                // Sleep for the designated poll interval
                Thread.Sleep(DEVICE_DISCOVERY_POLL_RATE);
            }
        }
 private void escaneo()
 {
     Debug.WriteLine("Inicio de escaneo");
      BluetoothClient cliente = new BluetoothClient();
      BluetoothDeviceInfo[] dispositivos = cliente.DiscoverDevicesInRange();
      Debug.WriteLine("\n"+dispositivos.Length.ToString() + " numero de dispositivos");
      foreach (BluetoothDeviceInfo blue in dispositivos)
      {
          Debug.WriteLine(blue.DeviceAddress + " " + blue.DeviceName);
          if (blue.DeviceAddress.ToString().Equals("0015FFF21179"))
          {
              Debug.WriteLine("tenemos un ganador!! " + blue.DeviceAddress.ToString());
              dispositivomeromero = blue;
          }
      }
     //201308021034
     if (parear()){
         Debug.WriteLine("Conectado!!");
         Thread tredi = new Thread(new ThreadStart(conectio));
         tredi.Start();
     }
 }
 public void scanRemoteDevices()
 {
     BluetoothRadio.PrimaryRadio.Mode = RadioMode.Connectable;
     BluetoothClient client = new BluetoothClient();
     _devices = client.DiscoverDevicesInRange();
 }
        private void Discovery(Object sender, DoWorkEventArgs e)
        {
            InfoMessage("Starting Discovery Round");

            var client = new BluetoothClient();

            BluetoothDeviceInfo[] availableDevices = client.DiscoverDevicesInRange(); // I've found this to be SLOW!

            String deviceList = "";

            BluetoothDeviceInfo tmpDI = null;

            foreach (BluetoothDeviceInfo device in availableDevices)
            {
                //ServiceRecord[] devServices = device.GetServiceRecords(OurServiceClassId);
                if (!device.Authenticated/* || devServices.Count() == 0*/)
                    continue;

                if (tmpDI == null)
                    tmpDI = device;

                deviceList += device.DeviceName + " : " + device.DeviceAddress + " : " + (device.Authenticated ? "Paired" : "Not Paired") + /*" : " + devServices.Count() + */"\n";
            }

            UpdateDiscoveryDevices(deviceList);

            if (tmpDI != null)
            {
                var peerclient = new BluetoothClient();
                peerclient.BeginConnect(tmpDI.DeviceAddress, OurServiceClassId, DiscoveryDeviceConnectCallback, peerclient);
            }
        }
        /// <summary>
        /// Scan for Zeemote
        /// <returns>true if device in range</returns>
        /// </summary>
        private bool ScanForDevice()
        {
            // ToDo: move btClient to the class level
            bgWorkerProcessData.ReportProgress(0, "Searching for the device...");
            BluetoothClient btClient = new BluetoothClient();
            BluetoothDeviceInfo[] devices = btClient.DiscoverDevicesInRange();
            //bgWorkerProcessData.ReportProgress(0, "Search complete");
            //bgWorkerProcessData.ReportProgress(0, "Devices discovered:");

            foreach (BluetoothDeviceInfo device in devices)
            {
                if (device.DeviceName == deviceName)
                {
                    deviceAddress = device.DeviceAddress;
                    bgWorkerProcessData.ReportProgress(0, deviceName + " found");
                    return true;
                }
            }

            return false;
        }