Oakrey.Guru.Can
6.0.0
dotnet add package Oakrey.Guru.Can --version 6.0.0
NuGet\Install-Package Oakrey.Guru.Can -Version 6.0.0
<PackageReference Include="Oakrey.Guru.Can" Version="6.0.0" />
<PackageVersion Include="Oakrey.Guru.Can" Version="6.0.0" />
<PackageReference Include="Oakrey.Guru.Can" />
paket add Oakrey.Guru.Can --version 6.0.0
#r "nuget: Oakrey.Guru.Can, 6.0.0"
#:package Oakrey.Guru.Can@6.0.0
#addin nuget:?package=Oakrey.Guru.Can&version=6.0.0
#tool nuget:?package=Oakrey.Guru.Can&version=6.0.0
Oakrey.Guru.Can
CAN and CAN-FD adapter library for Oakrey Guru USB hardware. Provides dual-channel bus configuration, per-channel filtering, bridge mode, reactive Rx streams, and simulation support on top of Oakrey.Guru.Base.
Main features
- Dual-channel CAN bus:
Channel.CAN0andChannel.CAN1controlled independently - CAN-FD support: configurable arbitration and data-phase baud rates, bit-rate switching, FD payload via
ConfigandCanTiming - Per-channel control: enable/disable, bus terminator, timing (
SamplePoint,TQCount,SyncJumpWidth), reset, reload - Message filtering: per-channel standard (0-127) and extended (0-63) ID filters;
IdFilter,RangeFilter,DualFilter; global filter policy viaGlobalFilter - Bridge mode: route traffic between channels with
BridgeMode(NONE / ALLOW / DENY); append specific IDs to a bridge list - Reactive Rx streams:
IObservable<ReceivedMessage>,IObservable<ReceivedCanEvent>,IObservable<DriverStatusChanged> - Simulation:
ISimGuruexposesWriteInputValueandGetSimCrcfor hardware-in-the-loop scenarios - License key retrieval:
IGuruLicensewith per-slot and boot license access - Inherits from
DeviceBase: firmware update, ping, bootloader reset,FwUpdateInProgressobservable
Architecture
classDiagram
class IDevice {
+Connect(ct)
+Ping(data, ct)
+GetFwVersion(ct)
+UpdateFirmware(path, ct)
+RestartToBootloader(ct)
+FwUpdateInProgress IObservable~bool~
}
class ICanGuru {
+ReceivedMessage IObservable~ReceivedMessage~
+ReceivedCanEvent IObservable~ReceivedCanEvent~
+CanDrvStatusChanged IObservable~DriverStatusChanged~
+Enable(channel, enable, ct)
+ConfigSet(channel, config, ct)
+FilterSet(channel, type, index, filter, ct)
+GlobalFilterSet(channel, globalFilter, ct)
+CanTimingSet(channel, canTiming, ct)
+SetBridgeMode(mode, ct)
+ClearBridgeMode(list, ct)
+AppendBridgeMode(list, ids, ct)
+Send(channel, message)
}
class ISimGuru {
+WriteInputValue(index, value, ct)
+GetSimCrc(ct)
}
class IGuruLicense {
+GetLicenseKey(id, ct)
+GetAllLicenseKeys(ct)
+GetBootLicense(ct)
}
class CanGuruAdapter {
+Create(serial, quid, ct)$ Task~CanGuruAdapter~
}
IDevice <|.. CanGuruAdapter
ICanGuru <|.. CanGuruAdapter
ISimGuru <|.. CanGuruAdapter
IGuruLicense <|.. CanGuruAdapter
Key data types
| Type | Description |
|---|---|
Config |
CAN/CAN-FD bus config: baud rates, FD enable, monitor-only |
CanTiming |
Nominal and data-phase timing: sample point, TQ count, SJW |
Message |
TX/RX message: identifier, FD flags, BRS, ESI, RTR, data |
ReceivedMessage |
Received message with hardware timestamp |
ReceivedCanEvent |
CAN event (e.g. bus error) with timestamp |
DriverStatusChanged |
Driver state transition notification |
BridgeMode |
Enum: NONE / ALLOW / DENY |
BridgeList |
Identifies a bridge pair (CAN0-CAN1) |
Channel |
Enum: CAN0 / CAN1 |
IdFilter / RangeFilter / DualFilter |
Concrete filter implementations |
Requirements
- .NET 11 (Windows only)
Oakrey.Guru.Base(package dependency)Oakrey.Log.Abstractions3.0 or newer- Oakrey Guru CAN USB hardware adapter
Installation
.NET CLI
dotnet add package Oakrey.Guru.Can
Package Manager Console
Install-Package Oakrey.Guru.Can
NuGet Package Manager
Search for Oakrey.Guru.Can in Visual Studio under Tools > NuGet Package Manager > Manage NuGet Packages for Solution.
Example usage
Create and connect
// serial: device serial number, quid: USB device qualifier GUID
CanGuruAdapter adapter = await CanGuruAdapter.Create(serial, quid, cancellationToken);
Configure and enable a channel
Config config = new()
{
ArbitrationBaudRate = 500_000,
FdDataPhaseBaudRate = 2_000_000,
FdEnable = true,
MonitorOnly = false,
};
await adapter.ConfigSet(Channel.CAN0, config, cancellationToken);
await adapter.TerminatorEnable(Channel.CAN0, true, cancellationToken);
await adapter.Enable(Channel.CAN0, true, cancellationToken);
Custom timing
CanTiming timing = new(
nominal: new Timing(samplePoint: 750, tQCount: 16, syncJumpWidth: 1),
data: new Timing(samplePoint: 750, tQCount: 8, syncJumpWidth: 1));
await adapter.CanTimingSet(Channel.CAN0, timing, cancellationToken);
Send a message
Message message = new()
{
Identifier = 0x1A0,
FDEnabled = true,
BitRateSwitchEnabled = true,
Data = [0x01, 0x02, 0x03, 0x04],
};
adapter.Send(Channel.CAN0, message);
Receive messages reactively
using IDisposable subscription = adapter.ReceivedMessage
.Subscribe(msg => Console.WriteLine($"ID: {msg.Message.Identifier:X} Data: {BitConverter.ToString(msg.Message.Data)}"));
Set a message filter
// Allow only IDs 0x100 to 0x1FF on CAN0 standard filters, slot 0
await adapter.FilterSet(Channel.CAN0, FilterType.Standard, 0, new RangeFilter(0x100, 0x1FF), cancellationToken);
await adapter.Reload(Channel.CAN0, cancellationToken);
Bridge mode
// Forward all traffic from CAN0 to CAN1
await adapter.SetBridgeMode(BridgeMode.ALLOW, cancellationToken);
// Forward only specific IDs
await adapter.AppendBridgeMode(BridgeList.CAN0_CAN1, [0x1A0, 0x1B0], cancellationToken);
Firmware update
adapter.FwUpdateInProgress.Subscribe(active =>
Console.WriteLine(active ? "Firmware update in progress..." : "Firmware update complete."));
await adapter.UpdateFirmware(@"C:\firmware\can_guru_v4.hex", cancellationToken);
Development notes
CanGuruAdapterissealed; use theICanGuru/ISimGuru/IGuruLicenseinterfaces in consuming code.- Filter changes require
Reloadto take effect;Resetclears all channel state. ReceivedMessage,ReceivedCanEvent, andCanDrvStatusChangedare hot observables backed bySubject; subscribe before enabling the channel to avoid missing early events.- All async methods accept a
CancellationTokenand propagate it through the handler pipeline. Sendis fire-and-forget (synchronous enqueue); use the Rx subscription to observe results.
Project information
| Field | Value |
|---|---|
| Author | Oakrey |
| License | MIT |
| Target framework | net11.0-windows |
| NuGet package | Oakrey.Guru.Can |
| Repository | https://dev.azure.com/oakrey/OpenPackages/_git/Drivers |
License
MIT. See the LICENSE file for details.
Package Manager Console
Run the following command in your Package Manager Console:
Install-Package Oakrey.Guru.Can
Requirements
- .NET 11 for Windows or higher
Project Information
- Author: Oakrey
- Company: Oakrey
- License: MIT
- Repository: Git Repository
- Project URL: Project Website
Contributing
Contributions are welcome! Feel free to open issues or submit pull requests to improve the package.
License
This project is licensed under the MIT License. See the LICENSE file for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0-windows7.0 is compatible. |
-
net11.0-windows7.0
- Oakrey.Guru.Base (>= 6.0.0)
- Oakrey.Log.Abstractions (>= 4.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.