问题
I'm trying to develop an app for Win 8.1 PC to communicate with my BLE device. I read that in Win 8 there is no something like scanning functionality for BLE so I read some examples from MS and try to simple connect to my device with UUID: "A9DA45B4-34F8-C660-591D-F6918B5B988C"
So I write some code based on ms examples:
var devices = await DeviceInformation.FindAllAsync(
GattDeviceService.GetDeviceSelectorFromUuid(new Guid("A9DA45B4-34F8-C660-591D-F6918B5B988C")), new string[] { "System.Devices.ContainerId" });
if (devices.Count > 0){
//Do something
}
But this code always return me empty devices list. More over I am still able to connect my device by Android or iOS app.
Can someone told me if it is good way to connect BLE?
回答1:
Go to Settings --> Change PC Settings --> --> PC and devices --> Bluetooth.
Make sure that your device is discoverable, then establish a connection.
Try again when you're done, if it still doesn't work, try with following code:
var devices = await DeviceInformation.FindAllAsync(
GattDeviceService.GetDeviceSelectorFromUuid(GattServiceUuids.GenericAccess));
devices.Count should return at least 1.
回答2:
In my case there were 3 things wrong.
If you plan to use BLE on Windows 8.1, first make sure that you have
Bluetooth LE Enumerator
In your Device Manager, if not go to PC/laptop manufacturer and reinstall your driver until you find BLE Enumerator in your device manager!
Second, as Peter Duniho said, pair your device manually before you do anything else. Windows doesn't have something like scan functionality so before you try to connect, pair it first.
And last, quoting Alexandru, Windows BLE is like "Wild West". Several times when I tried to pair my device with Windows, I got the message "Windows can't pair your device, make sure that it is still discoverable". To omit this step I increase each manufacturer timouts on my device (I think that when Windows tried to pair my device after rang was thinking that nothing happened because of too long delays and it goes to sleep mode or reject connection) so you must be patient. First, set each timeout to MAX value and turn off sleep modes and energy saving modes.
Also I can confirm that the following code works fine:
var devices = await DeviceInformation.FindAllAsync(
GattDeviceService.GetDeviceSelectorFromUuid(new Guid("A9DA45B4-34F8-C660-591D-F6918B5B988C")), new string[] { "System.Devices.ContainerId" });
来源:https://stackoverflow.com/questions/27152808/bluetooth-low-energy-connection