How to access bluetooth adapter on windows with C# | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How to access bluetooth adapter on windows with C#

Hello guys, am trying to access the windows in-built blueooth adapter from C# library known as Bluetooth LE (Low Energy). I have installed the nuget package and when I try to run my code, I get the error that Unhandled exception. System.ArgumentException: [Plugin.BluetoothLE] No platform plugin found. Did you install the nuget package in your app project as well?. I have tried looking online to see if there is a GATTServer instance that needs to be started but did not succeed. Please help me access the adapter correctly without this exception being thrown. Here is the C# code am trying to use public class BTClient { //define the adapter static IAdapter adapter; //declare variable to hold the UUID of a device string UUID; public BTClient() { //assign the adapter on constructor exit //this adapter allows usage across various platforms adapter = CrossBleAdapter.Current; } /// <summary> /// the method below is for discovering bluetooth devices /// nearby /// </summary> /// <returns></returns> [DllExport("devices", CallingConvention = CallingConvention.Cdecl),ComVisible(true)] public static List<Plugin.BluetoothLE.IDevice> DiscoverDevices() { IGattServer server = (IGattServer)CrossBleAdapter.Current.CreateGattServer(); server.CreateService(new Guid(), true); var devices = new List<Plugin.BluetoothLE.IDevice>(); var scanner = CrossBleAdapter.Current.Scan().Subscribe(scanResult => { devices.Add(scanResult.Device); }); return devices; } } class Solution{ static void Main(){ List<IDevice> devices = new List<IDevice>(); devices = BTClient.DiscoverDevices(); foreach(var device in devices){ Console.WriteLine(device.Name); } } How do I access the

18th Apr 2022, 2:37 PM
Timothy Njiru
Timothy Njiru - avatar
1 Answer