4

Update 2: Below are the details of where I am at the moment, but I didn't want the detail to derail any general answers that may bear on the base question of finding any path to BLE / GATT in WPF.

Build system version:

Microsoft Visual Studio Community 2017 
Version 15.7.4
VisualStudio.15.Release/15.7.4+27703.2035
Microsoft .NET Framework
Version 4.7.03056

So far, I have changed the project file to target windows 8.1, <TargetPlatformVersion>8.1</TargetPlatformVersion>.

Currently, I am getting local BLE advertisements, but when I try to access a GATT service:

var _service = await GattDeviceService.FromIdAsync(deviceId);

Update 1: I have attempted to include WinRT. Here is my Reference and it's properties:

Reference Properties

Any help will be greatly appreciated.

Sean Vikoren
  • 1,084
  • 1
  • 13
  • 24
  • In fact WinRT does not have such dll at all. Probably you referenced something wrong. Have you imported WinRT using WinMD? – Mike Petrichenko Oct 10 '18 at 05:03
  • @MikePetrichenko I have made an update above. Does that answer your question? – Sean Vikoren Oct 11 '18 at 23:09
  • It looks you have to reference some other files: https://learn.microsoft.com/en-us/windows/uwp/porting/desktop-to-uwp-enhance – Mike Petrichenko Oct 12 '18 at 00:11
  • @MikePetrichenko Thank you for the link. I will work through the instructions and get back to you soon. – Sean Vikoren Oct 12 '18 at 00:39
  • 1
    I was under the impression that GATT for BLE was not available until Win10, and even then not at first (Creator's Update, in 2017). See https://blogs.windows.com/buildingapps/2017/01/13/new-bluetooth-features-in-creators-update-gatt-server-bluetooth-le/. Note, that LE Peripheral supports the GATT client mode. Oh, and WPF doesn't do BLE directly, as @MikePetrichenko pointed out. Did I miss something? – bobwki Oct 12 '18 at 17:52
  • @MikePetrichenko I did follow the steps int he linked article and they did not alleviate the problem. As bobwki mentioned, this entire endeavor is a bit unusual and WPF does not seem to do BLE directly, hence my indirect attempt. – Sean Vikoren Oct 12 '18 at 23:31
  • @bobwki Thank you for the input. Since all I need is a GATT client, perhaps 'LE Peripheral' will enough of a clue for me. I'll take a look at that. – Sean Vikoren Oct 12 '18 at 23:32
  • In fact yes, WPF (and Desktop .NET apps) can not access WinRT directly if you do not write your own code. If you need GATT support it probably better to use third-party library. – Mike Petrichenko Oct 13 '18 at 10:06
  • @bobwki Do you have any more information about ' LE Peripheral '? It seemed to be coming up in relation to Android. – Sean Vikoren Oct 16 '18 at 23:40
  • @MikePetrichenko I would be very excited to find any working example with a library. Given that I am developing with VS 2017, all tested library based examples do not work. I have attempted approximately twenty so far. – Sean Vikoren Oct 16 '18 at 23:49
  • @Sean Vikoren [Bluetooth Framework](https://www.btframework.com/bluetoothframework.htm). Supports WinForms, WPF, Win Iot; .NET Standard, .NET Core, .NET Framework – Mike Petrichenko Oct 17 '18 at 00:53
  • May I ask specifically what BLE device you're working with ? – jsanalytics Oct 21 '18 at 10:07
  • @jsanalytics It's a custom built device being accessed from a windows tablet. – Sean Vikoren Oct 23 '18 at 18:44

1 Answers1

0

Install the Windows 10 SDK.

Then add three References for:

Windows
Windows.Foundation.FoundationContract
WindowsBase

Then set 'Copy Local' to 'true' in the properties.

Possible Location Hints:

D:\Windows Kits\10\UnionMetadata\10.0.17134.0\Windows.winmd
D:\Windows Kits\10\References\10.0.17134.0\Windows.Foundation.FoundationContract\3.0.0.0\en\Windows.Foundation.FoundationContract.xml
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\WindowsBase.dll

Be sure to do a full update on the target machine. As of this writing, there were a few items that did not work right until the Win10 update was done.

Another possible way to do this is through NuGet UWP-Desktop, though I never got the chance to try it.

Sean Vikoren
  • 1,084
  • 1
  • 13
  • 24