SimpleBLE

Examples

Code examples for SimpleSharpBLE.

The examples follow the C++ examples, with one file-based C# app per use case.

The Android scan app demonstrates Android initialization, runtime permissions, and background scanning.

Run an example

Each example is a single .cs file that .NET 10 runs directly. To run one against the published package, copy it and replace its first line, #:project ../../simplesharpble, with a package reference:

#:package SimpleSharpBLE@1.2.*

Then run it with dotnet run scan.cs.

To run the examples against the repository sources instead, build the native libraries and pass their directory to dotnet run:

cmake -S simplecble -B build_simplecble -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_LIBDIR=lib
cmake --build build_simplecble --config Release --parallel
cmake --install build_simplecble --config Release --prefix "$PWD/build_simplecble/install"
dotnet run examples/simplesharpble/scan.cs -p:NativeLibraryDirectory="$PWD/build_simplecble/install/lib"

On Windows, the DLLs are in build_simplecble/install/bin.

Central

ExampleDemonstrates
list_adaptersBackends and their adapters, plus the consolidated adapter list.
list_pairedPaired devices for each adapter.
power_cycleAdapter power control and events.
scanDiscovery events, signal strength, service data, and manufacturer data.
connectDevice selection, connection, MTU, services, characteristics, and descriptors.
multiconnectFive connect/disconnect cycles and connection events.
readCharacteristic selection and repeated reads.
writeAcknowledged or unacknowledged writes of hex bytes.
notifyNotifications and unsubscription.
indicateIndications and unsubscription.
notify_multiNotifications from two devices and staggered disconnection.

Peripheral

peripheral advertises a custom service, accepts reads and writes, echoes written values to subscribers, and reports client and subscription events. Press Ctrl+C to stop.

On this page