Oakrey.Capsule.Can
2.0.2
dotnet add package Oakrey.Capsule.Can --version 2.0.2
NuGet\Install-Package Oakrey.Capsule.Can -Version 2.0.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Oakrey.Capsule.Can" Version="2.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Oakrey.Capsule.Can" Version="2.0.2" />
<PackageReference Include="Oakrey.Capsule.Can" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Oakrey.Capsule.Can --version 2.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Oakrey.Capsule.Can, 2.0.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Oakrey.Capsule.Can@2.0.2
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Oakrey.Capsule.Can&version=2.0.2
#tool nuget:?package=Oakrey.Capsule.Can&version=2.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Oakrey.Capsule.Can
Overview
Oakrey.Capsule.Can is a .NET 10 class library for encoding and decoding CAN and CAN-FD communication data using the Oakrey Capsule binary framing protocol.
It provides three capsule types that cover the full lifecycle of a CAN channel:
| Capsule | Capsule ID | Purpose |
|---|---|---|
CanDataCapsule |
0x0101 |
CAN/CAN-FD message frames (single or batched) |
CanChannelInfoCapsule |
0x0100 |
Channel capability and runtime status |
CanChannelSettingCapsule |
0x0102 |
Channel configuration (baud rate, timing, filters) |
Main Features
- Serialize and deserialize CAN messages to and from the Capsule binary format.
- Multi-message batching in a single
CanDataCapsuleusing delta timestamps (CanStatus.MultiModeMessage). - CAN-FD support signaled via
CanStatus.FDEnabled. - Extended message IDs (
CanStatus.ExtendedMessage). - Channel capability flags: terminator present, FD support, timing override, filter support (
CanChannelFlags). - Full timing configuration: arbitration and data baud rates, sample points, time quanta, sync jump width.
- Request payload generation via static
GetRequestPayload()on each capsule type.
Architecture
classDiagram
class CapsuleBase {
+CapsuleHead Head
+Serialize() byte[]
#WritePayload(BinaryWriter)
}
class CanDataCapsule {
+ushort Id = 0x0101
+byte Version = 0x01
+IList~CanMessage~ Messages
+CanStatus Flag
+byte ChannelIndex
+GetRequestPayload()$ byte[]
}
class CanChannelInfoCapsule {
+ushort Id = 0x0100
+byte Version = 0x01
+byte ChannelIndex
+CanChannelStatus Status
+CanChannelFlags Setting
+uint MaxArbitrationBaudRate
+uint MaxDataBaudRate
+string Alias
+GetRequestPayload()$ byte[]
}
class CanChannelSettingCapsule {
+ushort Id = 0x0102
+byte Version = 0x01
+byte ChannelIndex
+CanChannelSettings Setting
+uint ArbitrationBaudRate
+uint DataBaudRate
+byte NominalSamplePoint
+ushort NominalTimeQuantaCount
+byte NominalSWJ
+byte DataSamplePoint
+byte DataTimeQuantaCount
+byte DataSWJ
+string Alias
+GetRequestPayload()$ byte[]
}
class CanMessage {
+long Id
+long Timestamp
+byte[] Data
+WriteTo(BinaryWriter)
+WriteTo(BinaryWriter, long timestamp)
}
class CanMessageFactory {
+FromPayload(ReadOnlySpan~byte~, out int)$ CanMessage
+FromPayload(ReadOnlySpan~byte~, out int, long)$ CanMessage
}
CapsuleBase <|-- CanDataCapsule
CapsuleBase <|-- CanChannelInfoCapsule
CapsuleBase <|-- CanChannelSettingCapsule
CanDataCapsule "1" --> "*" CanMessage
CanMessageFactory ..> CanMessage : creates
Requirements
- .NET 10 or higher
- NuGet dependency:
Oakrey.Collections 2.0.0 - NuGet dependency:
Oakrey.Capsule(project / package reference)
Installation
.NET CLI
dotnet add package Oakrey.Capsule.Can
Package Manager Console
Install-Package Oakrey.Capsule.Can
NuGet Package Manager
Search for Oakrey.Capsule.Can in Tools > NuGet Package Manager > Manage NuGet Packages for Solution.
Usage
Serialize a single CAN message
CanMessage message = new CanMessage(
timestamp: DateTime.UtcNow.Ticks,
iD: 0x1A0,
data: new byte[] { 0x01, 0x02, 0x03, 0x04 });
CanDataCapsule capsule = new CanDataCapsule(
record: message,
status: CanStatus.FDEnabled,
channel: 0,
hwId: 1);
byte[] binary = capsule.Serialize();
Serialize multiple CAN messages (batched)
IEnumerable<CanMessage> messages = GetMessages();
CanDataCapsule capsule = new CanDataCapsule(
records: messages,
status: CanStatus.FDEnabled,
channel: 0,
hwId: 1);
// CanStatus.MultiModeMessage is set automatically when more than one message is added.
byte[] binary = capsule.Serialize();
Deserialize a CAN data capsule
byte[] binary = ReceiveBinary();
CanDataCapsule capsule = new CanDataCapsule(binary);
foreach (CanMessage msg in capsule.Messages)
{
Console.WriteLine(msg); // timestamp; id; length; hex-data
}
Request channel information
// Build a request frame and send it to the device.
byte[] request = CanChannelInfoCapsule.GetRequestPayload();
// Parse the response.
byte[] response = SendAndReceive(request);
CanChannelInfoCapsule info = new CanChannelInfoCapsule(response);
Console.WriteLine($"Channel {info.ChannelIndex}: {info.Status}, FD={info.Setting.HasFlag(CanChannelFlags.SupportFD)}");
Configure channel settings
CanChannelSettingCapsule settings = new CanChannelSettingCapsule(
channelIndex: 0,
setting: CanChannelSettings.FDEnabled | CanChannelSettings.TerminatorEnabled,
arbitrationBaudRate: 500_000,
dataBaudRate: 2_000_000,
nominalSamplePoint: 80,
nominalTimeQuantaCount: 20,
nominalSWJ: 1,
dataSamplePoint: 75,
dataTimeQuantaCount: 10,
dataSWJ: 1,
alias: "CAN0");
byte[] binary = settings.Serialize();
Capsule Protocol Reference
| Type | Capsule ID | Version | Notes |
|---|---|---|---|
CanChannelInfoCapsule |
0x0100 |
0x01 |
Channel status and hardware capabilities |
CanDataCapsule |
0x0101 |
0x01 |
CAN frames; multi-message uses delta timestamps |
CanChannelSettingCapsule |
0x0102 |
0x01 |
Full timing and feature configuration |
Development Notes
- All capsules inherit from
CapsuleBaseand overrideWritePayload(BinaryWriter),Id, andVersion. - Delta timestamps in multi-message capsules are stored as
uint(max ~429 seconds at 100 ns tick resolution). CanMessageFactoryis the low-level deserialization entry point for individual frames within a payload.- All capsule types expose a static
GetRequestPayload()for polling devices that use a request/response model.
License
MIT. Copyright (c) Oakrey 2016-present.
See the project page and repository for more information.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Oakrey.Capsule.Base (>= 2.0.2)
- Oakrey.Collections (>= 2.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.