kirk-quinbar / heartratele Goto Github PK
View Code? Open in Web Editor NEWC#/WPF sample for calling WinRT apis to communicate with Bluetooth LE heart rate devices
License: MIT License
C#/WPF sample for calling WinRT apis to communicate with Bluetooth LE heart rate devices
License: MIT License
Your code works perfect in windows update 1709. I was able to create a WinForms application receiving measurements from a Polar H7.
I was looking for a method to check weather bluetooth support is available on the machine, but did not find any. Somewhere in the internet I found a code snippet like this:
public static async Task<bool> BluetoothIsSupportedAsync()
{
var radios = await Radio.GetRadiosAsync();
var bluetoothRadio = radios.FirstOrDefault(radio => radio.Kind == RadioKind.Bluetooth);
return bluetoothRadio != null;
}
But this isn't working. The GetRadiosAsync function is returning a __ComObject which cannot be evaluated.
Do you have any idea how to check if bluetooth is supported, bluetooth is enabled, bluetooth le is available.... ?
Brgds
Marcel
Any function returning devices should allow for filtering to only return heart rate devices. i believe the UWP samples from Microsoft may show how to do that.
Hi, Will this app work with Windows 8.1 for WPF? I installed VS 2015 on a Windows 8.1 machine and I am missing several references in the project. If I add the Windows 10 packages will this still function correctly on Windows 8.1?
1>------ Build started: Project: HeartRateLE.Bluetooth, Configuration: Debug Any CPU ------
1>C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Windows". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
1>C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Windows.Foundation.FoundationContract". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
1>C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Windows.Foundation.UniversalApiContract". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartRateMonitor.cs(8,15,8,22): error CS0234: The type or namespace name 'Devices' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartRateMonitor.cs(9,15,9,22): error CS0234: The type or namespace name 'Devices' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartRateMonitor.cs(10,15,10,22): error CS0234: The type or namespace name 'Devices' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartRateMonitor.cs(11,15,11,23): error CS0234: The type or namespace name 'Security' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\PairingHelper.cs(6,15,6,22): error CS0234: The type or namespace name 'Devices' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
1>C:\Users\NAEM\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\PairingHelper.cs(7,15,7,22): error CS0234: The type or namespace name 'Devices' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\Schema\BluetoothAttribute.cs(2,15,2,22): error CS0234: The type or namespace name 'Devices' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\Schema\DeviceSelectorInfo.cs(6,15,6,22): error CS0234: The type or namespace name 'Devices' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartDeviceWatcher.cs(6,15,6,22): error CS0234: The type or namespace name 'Devices' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartDeviceWatcher.cs(7,15,7,22): error CS0234: The type or namespace name 'Devices' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartDeviceWatcher.cs(8,15,8,22): error CS0234: The type or namespace name 'Devices' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\Utilities.cs(6,15,6,22): error CS0234: The type or namespace name 'Devices' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\Utilities.cs(7,15,7,22): error CS0234: The type or namespace name 'Devices' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\Utilities.cs(8,15,8,23): error CS0234: The type or namespace name 'Security' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\Utilities.cs(9,15,9,22): error CS0234: The type or namespace name 'Storage' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartRateMonitor.cs(263,52,263,69): error CS0246: The type or namespace name 'BluetoothLEDevice' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartRateMonitor.cs(273,44,273,62): error CS0246: The type or namespace name 'GattCharacteristic' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartRateMonitor.cs(273,71,273,96): error CS0246: The type or namespace name 'GattValueChangedEventArgs' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\PairingHelper.cs(37,53,37,83): error CS0246: The type or namespace name 'DeviceInformationCustomPairing' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\PairingHelper.cs(37,92,37,123): error CS0246: The type or namespace name 'DevicePairingRequestedEventArgs' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartDeviceWatcher.cs(90,30,90,43): error CS0246: The type or namespace name 'DeviceWatcher' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartDeviceWatcher.cs(95,43,95,56): error CS0246: The type or namespace name 'DeviceWatcher' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartDeviceWatcher.cs(124,34,124,47): error CS0246: The type or namespace name 'DeviceWatcher' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartDeviceWatcher.cs(124,56,124,73): error CS0246: The type or namespace name 'DeviceInformation' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartDeviceWatcher.cs(150,36,150,49): error CS0246: The type or namespace name 'DeviceWatcher' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartDeviceWatcher.cs(150,58,150,81): error CS0246: The type or namespace name 'DeviceInformationUpdate' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartDeviceWatcher.cs(172,36,172,49): error CS0246: The type or namespace name 'DeviceWatcher' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartDeviceWatcher.cs(172,58,172,81): error CS0246: The type or namespace name 'DeviceInformationUpdate' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\Utilities.cs(71,48,71,55): error CS0246: The type or namespace name 'IBuffer' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartRateMonitor.cs(17,17,17,34): error CS0246: The type or namespace name 'BluetoothLEDevice' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\ENAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartDeviceWatcher.cs(25,17,25,30): error CS0246: The type or namespace name 'DeviceWatcher' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartRateMonitor.cs(22,17,22,35): error CS0246: The type or namespace name 'GattCharacteristic' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\Schema\BluetoothAttribute.cs(16,35,16,52): error CS0246: The type or namespace name 'GattDeviceService' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\Schema\BluetoothAttribute.cs(22,35,22,53): error CS0246: The type or namespace name 'GattCharacteristic' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\Schema\BluetoothAttribute.cs(11,16,11,34): error CS0246: The type or namespace name 'GattCharacteristic' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\Schema\BluetoothAttribute.cs(12,16,12,30): error CS0246: The type or namespace name 'GattDescriptor' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\Schema\BluetoothAttribute.cs(14,16,14,33): error CS0246: The type or namespace name 'GattDeviceService' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\ENAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\Schema\DeviceSelectorInfo.cs(24,16,24,27): error CS0246: The type or namespace name 'DeviceClass' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\Schema\DeviceSelectorInfo.cs(30,16,30,37): error CS0246: The type or namespace name 'DeviceInformationKind' could not be found (are you missing a using directive or an assembly reference?)
Getting System.UnauthorizedAccessException, Access is Denied (E_ACCESSDENIED) error being thrown within the bluetooth library. Looks to be as available devices are enumerated and gattdeviceservice.getcharacteristics may be the culprit method. this too may be directly tied to the Windows Creator update the microsoft released
private async Task IsDeviceCompatible(string deviceId)
{
var compatibleDevice = true;
try
{
var device = await BluetoothLEDevice.FromIdAsync(deviceId);
//if filters were passed, check if the device name contains one of the names in the list
if (_filters != null)
{
compatibleDevice = _filters.Any(a => device.Name.CaseInsensitiveContains(a));
}
//filter out any devices that are not heart rate devices. with the current bluetooth apis, this will
//only occur if the device is paired. the windows creator update is supposed to allow for checking for this
//on unpaired devices, but a recent build completely broke bluetooth le support, so this is the best
//that can be done for now.
if (device.GattServices.Any() && compatibleDevice)
{
bool matches = true;
foreach (var requiredService in RequiredServices)
{
matches = CheckForCompatibility(device, requiredService.ToGuid());
if (!matches)
break;
}
compatibleDevice = matches;
}
}
catch
{
compatibleDevice = false;
}
return compatibleDevice;
}
Hello,
First i would like to thank you a lot for sharing with us this example in such random subject, we really appreciate that.
Now i have a question, is this plugin suppose to work with all types of Heart rate devices?
I am trying to test the example with different devices, i am able to find all my devices in scan result always but when it comes to pairing, i can pair my smart watch but not my other heart rate device that i am suppose the receive data from it. I always get failed as result of pairing request.
Some informations about the device:
-Activation time 60sec
-BLE version 4.x
The Windows version is: Windows 10 Pro 1803
I really appreciate if guide me through the reasons of not being able to pair to my device.
This may be related to the latest Windows Creator update per Bruce
http://www.drivethelife.com/windows-10/bluetooth-issue-windows-10-creators-update.html
For various Bluetooth issues, Microsoft recommends running the new Bluetooth Troubleshooter, a new troubleshooting tool you can find on the Settings page. Go to Settings > Update & security >Find and fix other problems > Troubleshoot.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.