Usn.Pb1151.DeviceKit
1.1.2
dotnet add package Usn.Pb1151.DeviceKit --version 1.1.2
NuGet\Install-Package Usn.Pb1151.DeviceKit -Version 1.1.2
<PackageReference Include="Usn.Pb1151.DeviceKit" Version="1.1.2" />
<PackageVersion Include="Usn.Pb1151.DeviceKit" Version="1.1.2" />
<PackageReference Include="Usn.Pb1151.DeviceKit" />
paket add Usn.Pb1151.DeviceKit --version 1.1.2
#r "nuget: Usn.Pb1151.DeviceKit, 1.1.2"
#:package Usn.Pb1151.DeviceKit@1.1.2
#addin nuget:?package=Usn.Pb1151.DeviceKit&version=1.1.2
#tool nuget:?package=Usn.Pb1151.DeviceKit&version=1.1.2
Usn.Pb1151.DeviceKit
A C# Serial/BLE interface library for the PB1151 microcontroller, developed for the PB1151 – Objektorientert programmering og databaser course at USN.
The library communicates with the microcontroller board (4 LEDs, 1 servo, 3 pushbuttons, a TMP102 temperature sensor, and an ADXL345 accelerometer) over a line-based JSON protocol, connected via either a USB serial port or Bluetooth Low Energy (Nordic UART Service). It is consumed as an object-oriented API — setting properties and subscribing to events — without direct handling of JSON or the underlying port.
The firmware for the kit and its interface description are available at PB1151vSnippets/Firmware/Micropython/jsonSerialAndBLE.
Install
dotnet add package Usn.Pb1151.DeviceKit
Requires .NET 10 on Windows (the BLE transport uses the Windows Runtime Bluetooth APIs).
Quick start
using System.Diagnostics;
using Usn.Pb1151.DeviceKit;
// Connect over USB serial...
var port = new SerialPortEx { PortName = "COM3", BaudRate = 9600 };
port.Open();
var controller = new JsonSerialController(port);
// ...or over BLE instead — same controller API either way.
// var ble = new BleNusEx("Pico-NUS");
// await ble.ConnectAsync(TimeSpan.FromSeconds(15));
// var controller = new JsonSerialController(ble);
// Turn LED1 on
controller.LedControl["LED1"].Value = 1;
// Move servo SV1 to 90 degrees
controller.ServoControl["SV1"].Angle = 90;
// React to a pushbutton
controller.ButtonControl["SW1"].ValueChanged += (s, e) =>
Debug.WriteLine($"{e.Id} = {e.Value}");
Usage
using System.Diagnostics;
using Usn.Pb1151.DeviceKit;
// SerialPortEx implements ISerialDataReadWrite; a plain SerialPort does not.
var port = new SerialPortEx { PortName = "COM3", BaudRate = 9600 };
port.Open();
var controller = new JsonSerialController(port);
// Outgoing: turn LED1 on
controller.LedControl["LED1"].Value = 1;
// Outgoing: move SV1 to 90 degrees, then let it go slack
controller.ServoControl["SV1"].Angle = 90;
controller.ServoControl.Release("SV1");
// Incoming: react to SW1
controller.ButtonControl["SW1"].ValueChanged += (s, e) =>
{
Debug.WriteLine($"{e.Id} = {e.Value}");
};
// Sensors: react to readings, then request them
controller.SensorControl["TEMP1"].DataChanged += (s, e) =>
{
var temp = (TempSensor)e.Sensor;
Debug.WriteLine($"{temp.Id}: {temp.Value} {temp.Unit}");
};
controller.SensorControl["ACC1"].DataChanged += (s, e) =>
{
var acc = (AccSensor)e.Sensor;
Debug.WriteLine($"{acc.Id}: x={acc.X} y={acc.Y} z={acc.Z} {acc.Unit}");
};
controller.SensorControl.SensorError += (s, e) =>
{
Debug.WriteLine($"{e.Id} error: {e.Error}");
};
controller.SensorControl.Read("TEMP1"); // one-shot read
controller.SensorControl.StartStream("ACC1", 50); // stream every 50 ms
controller.SensorControl.StopStream("ACC1"); // stop the stream
BleNusEx implements ISerialDataReadWrite too, so it drops in unchanged:
var ble = new BleNusEx("Pico-NUS");
await ble.ConnectAsync(TimeSpan.FromSeconds(15));
var controller = new JsonSerialController(ble);
Library contents
| Type | Purpose |
|---|---|
JsonSerialController |
Entry point. Owns LedControl, ServoControl, ButtonControl, SensorControl over one shared port. |
SerialPortEx |
ISerialDataReadWrite over a USB SerialPort. |
BleNusEx |
ISerialDataReadWrite over BLE (Nordic UART Service). Drop-in replacement for SerialPortEx. |
ISerialDataReadWrite |
The transport abstraction — implement it yourself to plug in a different transport or a test double. |
Documentation
Full API reference, JSON wire protocol, and sequence diagrams: JsonSerialController.md
Example project
A complete Windows Forms demo that consumes this library lives in the parent repository (SerialLedBtnLibEx) — see its README.md for a walkthrough of wiring the controller up to a GUI.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0-windows7.0 is compatible. net10.0-windows10.0.17763 is compatible. |
-
net10.0-windows10.0.17763
- System.IO.Ports (>= 10.0.9)
-
net10.0-windows7.0
- System.IO.Ports (>= 10.0.9)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
1.1.2: Small README documentation update; no API changes. 1.1.1: Updated README and package description/project URL; no API changes. 1.1.0: Multi-targeted the package for net10.0-windows and net10.0-windows10.0.17763.0, so it now restores in projects created from the standard WinForms/WPF templates (which target plain net10.0-windows) without editing the consuming project's TargetFramework. On net10.0-windows, everything is available except BleNusEx (BLE requires the WinRT projections only available on the versioned windows10.0.17763.0 TFM); bump the consuming project's TargetFramework to net10.0-windows10.0.17763.0 to use BLE. 1.0.1: Lowered the minimum target Windows version from 10.0.19041.0 to 10.0.17763.0 (Windows 10, version 1809) to relax consuming-project TargetFramework requirements; no API changes. 1.0.0: Initial release. JsonSerialController with LedControl, ServoControl, ButtonControl, and SensorControl (TMP102 temperature, ADXL345 acceleration). Two transports: SerialPortEx (USB serial) and BleNusEx (BLE Nordic UART Service), both behind ISerialDataReadWrite.