Beispiel #1
0
        /// <summary>
        /// Refreshes the available bluetooth devices as reported by Windows.
        /// If you do not see your device then check your bluetooth settings on
        /// your computer. Be sure that the device is present and paired.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void buttonRefresh_Click(object sender, RoutedEventArgs e)
        {
            var selector = BluetoothDevice.GetDeviceSelector();
            var devices  = await DeviceInformation.FindAllAsync(selector);

            comboBoxAvailableDevices.Items.Clear();

            foreach (var device in devices)
            {
                comboBoxAvailableDevices.Items.Add(device.Name);
            }

            try
            {
                CancelReadTask();

                if (streamSocket != null)
                {
                    streamSocket.Dispose();
                }
            }
            catch
            {
                dateStampOutput();
                outputTextBox.Text += "Exception on disposing streamsocket" + System.Environment.NewLine;
            }

            disableAllAcquistionButtons();
            dateStampOutput();
            outputTextBox.Text += "Bluetooth device list refreshed." + System.Environment.NewLine;
        }
Beispiel #2
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (_LineWatcher == null)
            {
                PhoneCallStore store = await PhoneCallManager.RequestStoreAsync();

                _LineWatcher              = store.RequestLineWatcher();
                _LineWatcher.LineAdded   += _watcher_LineAdded;
                _LineWatcher.LineRemoved += _watcher_LineRemoved;

                _LineWatcher.Start();
            }
            string str = PhoneLineTransportDevice.GetDeviceSelector(PhoneLineTransport.Bluetooth);

            if (_DeviceWatcher == null)
            {
                _DeviceWatcher          = DeviceInformation.CreateWatcher(str);
                _DeviceWatcher.Added   += _DeviceWatcher_Added;
                _DeviceWatcher.Removed += _DeviceWatcher_Removed;

                _DeviceWatcher.Start();
            }

            string str1  = BluetoothDevice.GetDeviceSelector();
            var    watch = DeviceInformation.CreateWatcher(str1);

            watch.Added   += _DeviceWatcher_Added;
            watch.Removed += _DeviceWatcher_Removed;
            watch.Start();
        }
 private async void Connect_Click(object sender, RoutedEventArgs e)
 {
     bluetoothList.Items.Clear();
     foreach (var info in await DeviceInformation.FindAllAsync(BluetoothDevice.GetDeviceSelector()))
     {
         bluetoothList.Items.Add(await BluetoothDevice.FromIdAsync(info.Id));
     }
 }
Beispiel #4
0
        async Task <DeviceInformation> IBluetoothService.PairAsync(string name)
        {
            var selector = BluetoothDevice.GetDeviceSelector();
            var devices  = await DeviceInformation.FindAllAsync(selector);

            var iPod = devices.FirstOrDefault(device => device.Name.ContainsIgnoringCase(name ?? "iPod"));

            if (iPod != null)
            {
                await iPod.Pairing.PairAsync(DevicePairingProtectionLevel.None);
            }

            return(iPod);
        }
Beispiel #5
0
        private async void UnpairAll()
        {
            var selector = BluetoothDevice.GetDeviceSelector();
            var devices  = await DeviceInformation.FindAllAsync(selector);

            foreach (var device in devices)
            {
                if (device.Name == Constants.DeviceName || device.Name == Constants.DeviceNameDebug)
                {
                    Console.WriteLine(tag, "Unpairing " + device.Id);
                    await device.Pairing.UnpairAsync();
                }
            }
        }
Beispiel #6
0
        public async Task InitBluetoothClient()
        {
            var informations = await DeviceInformation.FindAllAsync(BluetoothDevice.GetDeviceSelector());

            foreach (var info in informations)
            {
                Console.WriteLine(info.Name);
            }

            if (informations.Count == 0)
            {
                Console.WriteLine("デバイスが見つかりません");
                return;
            }

            var bluetoothDevice = await BluetoothDevice.FromIdAsync(informations[0].Id);

            var rfcommServices = await bluetoothDevice.GetRfcommServicesAsync();

            if (rfcommServices.Services.Count == 0)
            {
                Console.WriteLine("サービスがみつかりません");
                return;
            }

            var _service = rfcommServices.Services[0];

            var services =
                await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.ObexObjectPush));

            if (services.Count != 0)
            {
                Console.WriteLine(services[0].Id);
                _service = await RfcommDeviceService.FromIdAsync(services[0].Id);
            }
            else
            {
                Console.WriteLine("サービスが見つかりませんでした");
                return;
            }

            var _socket = new StreamSocket();

            await _socket.ConnectAsync(_service.ConnectionHostName, _service.ConnectionServiceName, SocketProtectionLevel.BluetoothEncryptionAllowNullAuthentication);

            StartStream(_socket);
        }
Beispiel #7
0
        private async void btnBlueLE02_Click(object sender, RoutedEventArgs e)
        {
            var selector = BluetoothDevice.GetDeviceSelector();

            //var con = selector.Where
            Debug.WriteLine(selector);
            var devices = await DeviceInformation.FindAllAsync(selector);

            if (devices.Count > 0)
            {
                Debug.WriteLine("Found {0} devices", devices.Count);
            }
            foreach (var item in devices)
            {
                var result = new BluetoothLEDeviceInfoModel(item);
                Debug.WriteLine(result.ToString());
            }
        }
        public override async Task <List <IBluetoothDevice> > GetPairedDevices()
        {
            var devices = new List <IBluetoothDevice>();

            var selector = BluetoothDevice.GetDeviceSelector();

            DeviceInformationCollection DeviceInfoCollection
                = await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort));

            //var pairedDevices = await DeviceInformation.FindAllAsync(selector);

            foreach (var deviceInfo in DeviceInfoCollection)
            {
                //var _service = await RfcommDeviceService.FromIdAsync(deviceInfo.Id);

                var device = new WindowsPhone81BluetoothDevice()
                {
                    Name = deviceInfo.Name, Address = string.Empty
                };

                device.BluetoothDevice = deviceInfo;


                var id = string.Empty;
                if (deviceInfo.Id.Contains("BTHENUM#{"))
                {
                    var index = deviceInfo.Id.IndexOf("BTHENUM#{") + 9;
                    id = deviceInfo.Id.Substring(index, 36);
                }

                if (!String.IsNullOrEmpty(id))
                {
                    var guid = Guid.Parse(id);
                    device.UniqueIdentifiers.Add(guid);
                }

                devices.Add(device);
            }

            return(devices);
        }
        static async Task <bool> IsPairedUnpair(AnkiBLE.anki_vehicle vehicle)
        {
            var selector = BluetoothDevice.GetDeviceSelector();
            var devices  = await DeviceInformation.FindAllAsync("System.Devices.DevObjectType:= 5 AND System.Devices.Aep.ProtocolId:=\"{bb7bb05e-5972-42b5-94fc-76eaa7084d49}\" AND (System.Devices.Aep.IsPaired:=System.StructuredQueryType.Boolean#True OR System.Devices.Aep.Bluetooth.IssueInquiry:=System.StructuredQueryType.Boolean#False)");

            if (devices.Count() > 0)
            {
                BluetoothLEDevice device = await BluetoothLEDevice.FromBluetoothAddressAsync(vehicle.mac_address);

                foreach (var dev in devices)
                {
                    if (dev.Id == device.DeviceInformation.Id)
                    {
                        await Unpair(vehicle);

                        return(true);
                    }
                }
            }
            return(false);
        }
        public void When_GetSelector()
        {
            string testSelector;

            testSelector = _deviceSelectorPrefix + "(System.Devices.Aep.IsPaired:=System.StructuredQueryType.Boolean#True OR " + _deviceSelectorIssueInquiry + "#False)";
            Assert.AreEqual(testSelector, BluetoothDevice.GetDeviceSelector());

            testSelector = _deviceSelectorPrefix + "(System.Devices.Aep.IsPaired:=System.StructuredQueryType.Boolean#True OR " + _deviceSelectorIssueInquiry + "#False)";
            Assert.AreEqual(testSelector, BluetoothDevice.GetDeviceSelectorFromPairingState(true));
            testSelector = _deviceSelectorPrefix + "(System.Devices.Aep.IsPaired:=System.StructuredQueryType.Boolean#False OR " + _deviceSelectorIssueInquiry + "#True)";
            Assert.AreEqual(testSelector, BluetoothDevice.GetDeviceSelectorFromPairingState(false));

            testSelector = _deviceSelectorPrefix + "(System.Devices.Aep.IsConnected:=System.StructuredQueryType.Boolean#True OR " + _deviceSelectorIssueInquiry + "#False)";
            Assert.AreEqual(testSelector, BluetoothDevice.GetDeviceSelectorFromConnectionStatus(BluetoothConnectionStatus.Connected));
            testSelector = _deviceSelectorPrefix + "(System.Devices.Aep.IsConnected:=System.StructuredQueryType.Boolean#False OR " + _deviceSelectorIssueInquiry + "#True)";
            Assert.AreEqual(testSelector, BluetoothDevice.GetDeviceSelectorFromConnectionStatus(BluetoothConnectionStatus.Disconnected));

            string deviceName = "TESTNAME";

            testSelector = _deviceSelectorPrefix + "(System.ItemNameDisplay:=\"" + deviceName + "\" OR " + _deviceSelectorIssueInquiry + "#True)";
            Assert.AreEqual(testSelector, BluetoothDevice.GetDeviceSelectorFromDeviceName(deviceName));
        }
Beispiel #11
0
        private async void InitializeRfcommServer()
        {
            var selector = BluetoothDevice.GetDeviceSelector();
            var devices  = await DeviceInformation.FindAllAsync(selector);

            comboBoxAvailableDevices.Items.Clear();

            foreach (var device in devices)
            {
                comboBoxAvailableDevices.Items.Add(device.Name);
            }
            try
            {
                string device1 = RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort);
                deviceCollection = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(device1);
            }
            catch (Exception exception)
            {
                dateStampOutput();
                outputTextBox.Text += "InitializeRfcommServer Exception: " + exception.ToString() + System.Environment.NewLine;
            }
        }
        private void uiCreate_Click(object sender, RoutedEventArgs e)
        {
            uiResultMsg.Text = "Creating query...";
            bool bBLE = (uiBTtype.SelectedValue as ComboBoxItem).Content.ToString().Contains("LE");

            switch ((uiQuery.SelectedValue as ComboBoxItem).Content.ToString())
            {
            case "GetDeviceSelector":
                if (bBLE)
                {
                    uiResultMsg.Text = BluetoothLEDevice.GetDeviceSelector();
                }
                else
                {
                    uiResultMsg.Text = BluetoothDevice.GetDeviceSelector();
                }
                break;

            case "GetDeviceSelectorFromPairingState(true)":
                if (bBLE)
                {
                    uiResultMsg.Text = BluetoothLEDevice.GetDeviceSelectorFromPairingState(true);
                }
                else
                {
                    uiResultMsg.Text = BluetoothDevice.GetDeviceSelectorFromPairingState(true);
                }
                break;

            case "GetDeviceSelectorFromPairingState(false)":
                if (bBLE)
                {
                    uiResultMsg.Text = BluetoothLEDevice.GetDeviceSelectorFromPairingState(false);
                }
                else
                {
                    uiResultMsg.Text = BluetoothDevice.GetDeviceSelectorFromPairingState(false);
                }
                break;

            case "GetDeviceSelectorFromConnectionStatus(Connected)":
                if (bBLE)
                {
                    uiResultMsg.Text = BluetoothLEDevice.GetDeviceSelectorFromConnectionStatus(BluetoothConnectionStatus.Connected);
                }
                else
                {
                    uiResultMsg.Text = BluetoothDevice.GetDeviceSelectorFromConnectionStatus(BluetoothConnectionStatus.Connected);
                }
                break;

            case "GetDeviceSelectorFromConnectionStatus(Disconnected)":
                if (bBLE)
                {
                    uiResultMsg.Text = BluetoothLEDevice.GetDeviceSelectorFromConnectionStatus(BluetoothConnectionStatus.Disconnected);
                }
                else
                {
                    uiResultMsg.Text = BluetoothDevice.GetDeviceSelectorFromConnectionStatus(BluetoothConnectionStatus.Disconnected);
                }
                break;

            default:
                uiResultMsg.Text = "Unknown value in second ComboBox";
                break;
            }
        }
Beispiel #13
0
        public async static Task <DeviceInformationCollection> GetSerialDevices()
        {
            string deviceSelector = RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort);

            return(await DeviceInformation.FindAllAsync(BluetoothDevice.GetDeviceSelector()));
        }
Beispiel #14
0
 /// <summary>
 /// To gets list of paired device
 /// </summary>
 /// <returns>When this method completes successfully, it returns a List of PenInformation that represents the specified pen</returns>
 public async Task <List <PenInformation> > FindPairedDevices()
 {
     return(await SearchDevicesWithoutWatcher(BluetoothDevice.GetDeviceSelector()));
 }
Beispiel #15
0
        public async Task init()
        {
            using (var con = new SQLiteConnection(dbName)) {
                con.Open();

                using (var cmd = con.CreateCommand()) {
                    cmd.CommandText = "CREATE TABLE IF NOT EXISTS text(ID INTEGER PRIMARY KEY AUTOINCREMENT, datetime INT, line TEXT) ";
                    cmd.ExecuteNonQuery();
                }
            }

            var informations = await DeviceInformation.FindAllAsync(BluetoothDevice.GetDeviceSelector());

            foreach (var info in informations)
            {
                Console.WriteLine(info.Name);
            }

            if (informations.Count == 0)
            {
                Console.WriteLine("デバイスが見つかりません");
                return;
            }

            var bluetoothDevice = await BluetoothDevice.FromIdAsync(informations[0].Id);

            var rfcommServices = await bluetoothDevice.GetRfcommServicesAsync();

            if (rfcommServices.Services.Count == 0)
            {
                Console.WriteLine("サービスがみつかりません");
                return;
            }

            _service = rfcommServices.Services[0];

            var services =
                await DeviceInformation.FindAllAsync(
                    RfcommDeviceService.GetDeviceSelector(
                        RfcommServiceId.ObexObjectPush));

            if (services.Count != 0)
            {
                _service = await RfcommDeviceService.FromIdAsync(services[0].Id);
            }
            else
            {
                Console.WriteLine("サービスが見つかりませんでした");
                return;
            }

            _socket = new StreamSocket();

            await _socket.ConnectAsync(_service.ConnectionHostName, _service.ConnectionServiceName, SocketProtectionLevel.BluetoothEncryptionAllowNullAuthentication);

            writer = new DataWriter(_socket.OutputStream);
            reader = new DataReader(_socket.InputStream);
            Console.WriteLine(_service.ConnectionHostName.ToString());
            Console.WriteLine("connected");
            receive();

            try {
                HttpListener httplistener = new HttpListener();
                httplistener.Prefixes.Add("http://localhost:8000/");
                httplistener.Start();
                while (true)
                {
                    var context = httplistener.GetContext();
                    var res     = context.Response;
                    var req     = context.Request;
                    var param   = "";
                    using (var reader = new StreamReader(req.InputStream, Encoding.GetEncoding("utf-8"))) {
                        param = reader.ReadToEnd();
                    }

                    await send(param);

                    res.StatusCode = 200;
                    res.Close();
                }
            } catch (Exception ex) {
                Console.WriteLine("Error: " + ex.Message);
            }
        }
        public static async Task <DeviceInformationCollection> FindPairedDevices()
        {
            var defaultSelector = BluetoothDevice.GetDeviceSelector();

            return(await DeviceInformation.FindAllAsync(defaultSelector));
        }
 private async Task <List <DeviceInformation> > GetBluetoothPairedDevices()
 {
     return(await GetDevices(BluetoothDevice.GetDeviceSelector()));
 }