Quick.Xamarin.BLE 1.0.4

Xamarin plugin to access Bluetooth Low Energy quickly and easily on Xamarin.Forms and Xamarin.Android or Xamarin.iOS.

Requires NuGet 2.8.1 or higher.

Install-Package Quick.Xamarin.BLE -Version 1.0.4
dotnet add package Quick.Xamarin.BLE --version 1.0.4
<PackageReference Include="Quick.Xamarin.BLE" Version="1.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Quick.Xamarin.BLE --version 1.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Quick Xamarin BLE

GitHub

Limitations

xamarin.android API LEVEL>=18
xamarin.ios ios SDK>=7

Permission

Android
AndroidManifest add permission

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

Start

Initialization

IBle ble = CrossBle.Createble(); 

Scan Bluetooth

 ble.OnScanDevicesIn += (sender, device) =>
 {
     Device.BeginInvokeOnMainThread(() =>
     { 
          //use device.Name or Uuid or Rssi or connect dev
          IDev dev=device;
     });
 };
 //start scan
 ble.StartScanningForDevices();

Stop scan

 ble.StopScanningForDevices();

Device connect

 dev.ConnectToDevice();

Device disconnect

dev.DisconnectDevice();

Bluetooth device Status callback event

 ble.AdapterStatusChange += (sender,Status) =>
 {
	 Device.BeginInvokeOnMainThread(() =>
     { 
		 if (Status == AdapterConnectStatus.Connected)//Connect
		 if (Status == AdapterConnectStatus.None)//disconnect
     });
 };

Get device characteristics

  List<IGattCharacteristic> cha= new List<IGattCharacteristic>();
 dev.CharacteristicsDiscovered(value=>
 {  
     Device.BeginInvokeOnMainThread(() =>
     {   
	     //save value to list and use
	     cha.Add(chvaluea); 
     });
 });

Get characteristics properties

cha[n].CanRead();
cha[n].CanWrite();
cha[n].CanNotify();

Read

//Call once
Search.ble.ServerCallBackEvent += (uuid, value) => 
{

};

cha[n].ReadCallBack();

or

var value=await cha[n].ReadCallBack();

Write

  cha[n].Write(byte[]);

Notify

 cha[n].NotifyEvent += SelectCharacteristic_NotifyEvent;
 cha[n].Notify();

Stop Notify

enter code here
 cha[n].StopNotify();
 cha[n].NotifyEvent -= SelectCharacteristic_NotifyEvent;

Notify Event

 private void SelectCharacteristic_NotifyEvent(object sender, byte[] value)
 {
     Device.BeginInvokeOnMainThread(() => { 
     });
 }

Important limitations

  • Event must be added Device.BeginInvokeOnMainThread
  • Characteristicsmust be 1-2 seconds after the Bluetooth connection
  • Bluetooth can only connect one at a time,When you want to connect other,Must call DisconnectDevice() first

Quick Xamarin BLE

GitHub

Limitations

xamarin.android API LEVEL>=18
xamarin.ios ios SDK>=7

Permission

Android
AndroidManifest add permission

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

Start

Initialization

IBle ble = CrossBle.Createble(); 

Scan Bluetooth

 ble.OnScanDevicesIn += (sender, device) =>
 {
     Device.BeginInvokeOnMainThread(() =>
     { 
          //use device.Name or Uuid or Rssi or connect dev
          IDev dev=device;
     });
 };
 //start scan
 ble.StartScanningForDevices();

Stop scan

 ble.StopScanningForDevices();

Device connect

 dev.ConnectToDevice();

Device disconnect

dev.DisconnectDevice();

Bluetooth device Status callback event

 ble.AdapterStatusChange += (sender,Status) =>
 {
	 Device.BeginInvokeOnMainThread(() =>
     { 
		 if (Status == AdapterConnectStatus.Connected)//Connect
		 if (Status == AdapterConnectStatus.None)//disconnect
     });
 };

Get device characteristics

  List<IGattCharacteristic> cha= new List<IGattCharacteristic>();
 dev.CharacteristicsDiscovered(value=>
 {  
     Device.BeginInvokeOnMainThread(() =>
     {   
	     //save value to list and use
	     cha.Add(chvaluea); 
     });
 });

Get characteristics properties

cha[n].CanRead();
cha[n].CanWrite();
cha[n].CanNotify();

Read

//Call once
Search.ble.ServerCallBackEvent += (uuid, value) => 
{

};

cha[n].ReadCallBack();

or

var value=await cha[n].ReadCallBack();

Write

  cha[n].Write(byte[]);

Notify

 cha[n].NotifyEvent += SelectCharacteristic_NotifyEvent;
 cha[n].Notify();

Stop Notify

enter code here
 cha[n].StopNotify();
 cha[n].NotifyEvent -= SelectCharacteristic_NotifyEvent;

Notify Event

 private void SelectCharacteristic_NotifyEvent(object sender, byte[] value)
 {
     Device.BeginInvokeOnMainThread(() => { 
     });
 }

Important limitations

  • Event must be added Device.BeginInvokeOnMainThread
  • Characteristicsmust be 1-2 seconds after the Bluetooth connection
  • Bluetooth can only connect one at a time,When you want to connect other,Must call DisconnectDevice() first

Dependencies

This package has no dependencies.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.4 473 1/24/2019