Oakrey.Emu.Can
5.0.0
dotnet add package Oakrey.Emu.Can --version 5.0.0
NuGet\Install-Package Oakrey.Emu.Can -Version 5.0.0
<PackageReference Include="Oakrey.Emu.Can" Version="5.0.0" />
<PackageVersion Include="Oakrey.Emu.Can" Version="5.0.0" />
<PackageReference Include="Oakrey.Emu.Can" />
paket add Oakrey.Emu.Can --version 5.0.0
#r "nuget: Oakrey.Emu.Can, 5.0.0"
#:package Oakrey.Emu.Can@5.0.0
#addin nuget:?package=Oakrey.Emu.Can&version=5.0.0
#tool nuget:?package=Oakrey.Emu.Can&version=5.0.0
Oakrey.Emu.Can
Overview
Oakrey.Emu.Can is a .NET library for communicating with Oakrey Guru Emu USB hardware that operates as a CAN bus emulator. It provides a thin, async-first adapter layer over Oakrey.Guru.Base that lets a host application write indexed simulation input values into the hardware and verify the active emulation profile via CRC.
Typical use case is hardware-in-the-loop (HIL) testing where the Emu device injects controlled CAN signal values into a device under test.
Main Features
- WriteInputValue - write a 16-bit value to a numbered simulation input channel on the connected Emu device.
- GetSimCrc - retrieve a 32-bit CRC of the currently loaded emulation profile, useful for verifying that the expected profile is active.
- Fully async API with
CancellationTokensupport throughout. - USB connection identified by serial number and QUID string.
- Thin interface
ICanEmuallows easy mocking in unit tests.
Architecture
classDiagram
direction LR
class ICanEmu {
+GetSimCrc(CancellationToken) Task~uint~
+WriteInputValue(uint index, ushort value, CancellationToken) Task
}
class CanEmuAdapter {
+Create(serial, quid, CancellationToken) Task~CanEmuAdapter~
+GetSimCrc(CancellationToken) Task~uint~
+WriteInputValue(uint, ushort, CancellationToken) Task
}
class SimCrcHandler {
+Id: 0x0B01
+Execute(...) Task~uint~
}
class WriteDriverValueHandler {
+Id: 0x0B00
+Execute(...) Task~uint~
}
ICanEmu <|.. CanEmuAdapter
CanEmuAdapter --> SimCrcHandler
CanEmuAdapter --> WriteDriverValueHandler
Project structure
Emu.Can/
ICanEmu.cs # Public interface
CanEmuAdapter.cs # Concrete adapter, factory method Create()
Handlers/
SimCrcHandler.cs # Protocol handler for GetSimCrc (cmd 0x0B01)
WriteDriverValueHandler.cs # Protocol handler for WriteInputValue (cmd 0x0B00)
Requirements
- .NET 11, Windows (net11.0-windows)
Oakrey.Guru.Base(included as a project/package dependency)Oakrey.Log.Abstractions3.0 or newer- Oakrey Guru Emu USB hardware device
Installation
.NET CLI
dotnet add package Oakrey.Emu.Can
Package Manager Console
Install-Package Oakrey.Emu.Can
NuGet Package Manager
Search for Oakrey.Emu.Can in Tools > NuGet Package Manager > Manage NuGet Packages for Solution and click Install.
Example Usage
Connect and write a simulation input value
using Oakrey.Emu.Can;
string serial = "YOUR_DEVICE_SERIAL";
string quid = "YOUR_DEVICE_QUID";
CanEmuAdapter adapter = await CanEmuAdapter.Create(serial, quid, CancellationToken.None);
// Write value 1234 to simulation input channel 0
await adapter.WriteInputValue(index: 0, value: 1234, CancellationToken.None);
adapter.Dispose();
Verify the active emulation profile via CRC
CanEmuAdapter adapter = await CanEmuAdapter.Create(serial, quid, CancellationToken.None);
uint crc = await adapter.GetSimCrc(CancellationToken.None);
Console.WriteLine($"Profile CRC: 0x{crc:X8}");
adapter.Dispose();
Using the interface for testability
public class MySimService
{
private readonly ICanEmu _emu;
public MySimService(ICanEmu emu) => _emu = emu;
public Task SetThrottle(ushort value, CancellationToken ct)
=> _emu.WriteInputValue(index: 5, value, ct);
}
Development Notes
- The USB connection is established inside
CanEmuAdapter.Create()which is the only public factory. The constructor is private. - Command IDs are fixed in the hardware protocol:
WriteInputValueuses0x0B00,GetSimCrcuses0x0B01. WriteInputValuereturns error code3from firmware when the index or value is out of range; the handler translates this toArgumentException.DeviceBase(fromOakrey.Guru.Base) manages the USB transceiver lifecycle and exposesDispose().- Pass
CancellationTokenfrom your application layer to support timeouts and cooperative cancellation.
Project Information
| Field | Value |
|---|---|
| Package ID | Oakrey.Emu.Can |
| Version | 5.0.0 |
| Author | Oakrey |
| License | MIT |
| Target | net11.0-windows |
| Repository | https://dev.azure.com/oakrey/OpenPackages/_git/Drivers |
| Project URL | https://www.oakrey.cz/opkg_drivers_guru |
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.