Skip to content

BGLibExt/BGLibExt.NET

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code
This branch is 32 commits ahead of jedinja:master.

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.

BGLibExt

A higher abstraction level .NET library for Silicon Labs/Bluegiga BLE112 modules.

This library is based on jedinja/monomyo and jrowberg/bglib, so thanks go out to them for their work. The BGLib was left as it was and the higher level abstraction code from jedinja/monomyo was refactored to be used as a library and some BLE advertisement related features have been added. For version 2.0 BGLibExt has been almost completely rewritten, because there were a lot of things that required a clean up.

Installation

Install nuget package BGLibExt

Usage

Discover devices

var bgLib = new BGLib();
var bleModuleConnection = new BleModuleConnection(bgLib);
bleModuleConnection.Start("COM1");

var bleDeviceDiscovery = new BleDeviceDiscovery(bgLib, bleModuleConnection);
bleDeviceDiscovery.ScanResponse += (sender, args) =>
{
};
bleDeviceDiscovery.StartDeviceDiscovery();
await Task.Delay(10000);
bleDeviceDiscovery.StopDeviceDiscovery();

bleModuleConnection.Stop();

Connect to device

var bgLib = new BGLib();
var bleModuleConnection = new BleModuleConnection(bgLib);
bleModuleConnection.Start("COM1");

var bleDeviceManager = new BleDeviceManager(bgLib, bleModuleConnection);
var bleDevice = await bleDeviceManager.ConnectAsync(address, addressType);

bleModuleConnection.Stop();

Disconnect from device

var bgLib = new BGLib();
var bleModuleConnection = new BleModuleConnection(bgLib);
bleModuleConnection.Start("COM1");

var bleDeviceManager = new BleDeviceManager(bgLib, bleModuleConnection);
var bleDevice = await bleDeviceManager.ConnectAsync(address, addressType);
await bleDevice.DisconnectAsync();

bleModuleConnection.Stop();

Read characteristic

var bgLib = new BGLib();
var bleModuleConnection = new BleModuleConnection(bgLib);
bleModuleConnection.Start("COM1");

var bleDeviceManager = new BleDeviceManager(bgLib, bleModuleConnection);
var bleDevice = await bleDeviceManager.ConnectAsync(address, addressType);
var data = await bleDevice.CharacteristicsByUuid[characteristicId].ReadValueAsync();
await bleDevice.DisconnectAsync();

bleModuleConnection.Stop();

Write characteristic

var bgLib = new BGLib();
var bleModuleConnection = new BleModuleConnection(bgLib);
bleModuleConnection.Start("COM1");

var bleDeviceManager = new BleDeviceManager(bgLib, bleModuleConnection);
var bleDevice = await bleDeviceManager.ConnectAsync(address, addressType);
var data = new byte[] { 1, 2, 3, 4 };
await bleDevice.CharacteristicsByUuid[characteristicId].WriteValueAsync(data);
await bleDevice.DisconnectAsync();

bleModuleConnection.Stop();

Characteristic value changed notifications

var bgLib = new BGLib();
var bleModuleConnection = new BleModuleConnection(bgLib);
bleModuleConnection.Start("COM1");

var bleDeviceManager = new BleDeviceManager(bgLib, bleModuleConnection);
var bleDevice = await bleDeviceManager.ConnectAsync(address, addressType);
bleDevice.CharacteristicsByUuid[characteristicId].ValueChanged += (sender, args) =>
{
}
await bleDevice.CharacteristicsByUuid[characteristicId].WriteCccAsync(BleCccValue.NotificationsEnabled);
await Task.Delay(10000);
await bleDevice.DisconnectAsync();

bleModuleConnection.Stop();

About

A higher abstraction level .NET library for Silicon Labs/Bluegiga BLE112 modules

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%