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
| Example | Demonstrates |
|---|---|
| list_adapters | Backends and their adapters, plus the consolidated adapter list. |
| list_paired | Paired devices for each adapter. |
| power_cycle | Adapter power control and events. |
| scan | Discovery events, signal strength, service data, and manufacturer data. |
| connect | Device selection, connection, MTU, services, characteristics, and descriptors. |
| multiconnect | Five connect/disconnect cycles and connection events. |
| read | Characteristic selection and repeated reads. |
| write | Acknowledged or unacknowledged writes of hex bytes. |
| notify | Notifications and unsubscription. |
| indicate | Indications and unsubscription. |
| notify_multi | Notifications 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.
