Pamoja.Serial
0.1.17
dotnet add package Pamoja.Serial --version 0.1.17
NuGet\Install-Package Pamoja.Serial -Version 0.1.17
<PackageReference Include="Pamoja.Serial" Version="0.1.17" />
<PackageVersion Include="Pamoja.Serial" Version="0.1.17" />
<PackageReference Include="Pamoja.Serial" />
paket add Pamoja.Serial --version 0.1.17
#r "nuget: Pamoja.Serial, 0.1.17"
#:package Pamoja.Serial@0.1.17
#addin nuget:?package=Pamoja.Serial&version=0.1.17
#tool nuget:?package=Pamoja.Serial&version=0.1.17
Pamoja.Serial
SLIP and COBS byte stuffing with streaming decoders, so a UART byte stream carries discrete packets. One capability of pamoja, one memory-safe Rust core with bindings for TypeScript, Python, and C#.
Install
dotnet add package Pamoja.Serial
using Pamoja.Serial;
This pulls in Pamoja.Native, the compiled engine, and Pamoja.Codec. dotnet add package Pamoja is the whole framework in one package.
Example
The guide project's example, spliced here as it ran in CI.
From bindings/dotnet/samples/Pamoja.Guides/SerialGuide.cs:
// A UART carries bytes, not packets, so a framing has to mark where one packet
// ends. SLIP reserves two byte values for that, and the package names both: the
// end byte closes a frame, the escape byte carries a value that would otherwise
// look like one.
byte[] payload = [.. "lvl="u8, Serial.SlipEnd, Serial.SlipEsc];
byte[] framed = Serial.SlipEncode(payload);
Console.WriteLine($"slip {payload.Length} payload bytes framed as {framed.Length}");
// Decoding gives the payload back unchanged, reserved bytes and all.
byte[] restored = Serial.SlipDecode(framed);
Console.WriteLine($"slip decoded back to {restored.Length} bytes");
// COBS trades that escaping for one code byte per run of up to 254 non-zero bytes,
// each run led by its own length, so a frame never grows by more than a byte per
// 254. Zero is the delimiter, and never appears inside a frame.
byte[] packet = [.. "lvl="u8, Serial.CobsDelimiter, .. "7"u8];
byte[] cobsFramed = Serial.CobsEncode(packet);
Console.WriteLine($"cobs {packet.Length} payload bytes framed as {cobsFramed.Length}");
// A read from a port returns whatever arrived, which is rarely one whole frame.
// This chunk holds two good frames with a truncated one between them; the decoder
// hands over the good ones and discards only the bad frame.
using SlipDecoder decoder = new();
byte[] chunk =
[
.. "ok"u8,
Serial.SlipEnd,
Serial.SlipEsc, // a frame that ends before its escape pair completes
Serial.SlipEnd,
.. "go"u8,
Serial.SlipEnd,
];
IReadOnlyList<byte[]> frames = decoder.Feed(chunk);
foreach (byte[] frame in frames)
{
Console.WriteLine($"received {System.Text.Encoding.UTF8.GetString(frame)}");
}
Console.WriteLine($"discarded {decoder.Discarded} frame the stream mangled");
The same capability in every language
| Language | Package | Reference |
|---|---|---|
| Rust | pamoja-serial |
reference, docs.rs, install |
| TypeScript | @pamoja/serial |
reference, install |
| Python | pamoja-serial |
reference, install |
| C# | Pamoja.Serial |
reference, install |
Documentation
Pamoja.Serialreference, every type in this namespace.- The Serial framing guide, with the same example in Rust, TypeScript, and Python.
- Every capability, and the install page.
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Pamoja.Codec (>= 0.1.17)
- Pamoja.Native (>= 0.1.17)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Pamoja.Serial:
| Package | Downloads |
|---|---|
|
Pamoja
The whole pamoja framework in one package: every capability of one memory-safe Rust core, behind an idiomatic C# facade, for IoT, robotics, and drones. |
|
|
Pamoja.FieldIo
Field I/O: The wires a gateway actually has: framed serial packets, an RS485 request and the reply it draws, a CAN frame, and the address a chip answers on. |
GitHub repositories
This package is not used by any popular GitHub repositories.