CanHub.Adapter.Virtual
1.0.1
dotnet add package CanHub.Adapter.Virtual --version 1.0.1
NuGet\Install-Package CanHub.Adapter.Virtual -Version 1.0.1
<PackageReference Include="CanHub.Adapter.Virtual" Version="1.0.1" />
<PackageVersion Include="CanHub.Adapter.Virtual" Version="1.0.1" />
<PackageReference Include="CanHub.Adapter.Virtual" />
paket add CanHub.Adapter.Virtual --version 1.0.1
#r "nuget: CanHub.Adapter.Virtual, 1.0.1"
#:package CanHub.Adapter.Virtual@1.0.1
#addin nuget:?package=CanHub.Adapter.Virtual&version=1.0.1
#tool nuget:?package=CanHub.Adapter.Virtual&version=1.0.1
CanHub.Adapter.Virtual
CanHub.Adapter.Virtual provides an in-process CAN/CAN FD adapter for tests, demos, and local tooling. It requires no hardware or native driver and is useful for validating application logic before connecting real devices.
Install
dotnet add package CanHub.Core
dotnet add package CanHub.Adapter.Virtual
Register
using CanHub;
using CanHub.Adapter.Virtual;
var registry = CanHubRegistry.CreateDefault()
.AddVirtualAdapter();
Endpoint Format
virtual://{busName}?channelIndex={channelIndex}
Examples:
virtual://demo?channelIndex=0
virtual://demo?channelIndex=1
virtual://isolated-test?channelIndex=0
Endpoints with the same bus name share the same in-process virtual bus. The adapter accepts legacy channel as a compatibility alias for channelIndex. Use different bus names to isolate tests. Bus names are case-sensitive.
Usage
await using var tx = await registry.OpenAsync(
"virtual://demo?channelIndex=0",
new CanOpenOptions { BusParameters = CanBusParameters.Classic500k },
CancellationToken.None);
await using var rx = await registry.OpenAsync(
"virtual://demo?channelIndex=1",
new CanOpenOptions { BusParameters = CanBusParameters.Classic500k },
CancellationToken.None);
using var subscription = rx.Subscribe(new CanSubscriptionOptions());
await tx.SendAsync(
CanFrame.CreateData(CanId.Standard(0x123), new byte[] { 0x01, 0x02 }),
ct: CancellationToken.None);
The adapter supports classic CAN and CAN FD frames. Scanning is intentionally not supported because virtual buses are created from endpoint names.
Testing Notes
The virtual adapter is deterministic and hardware-free, so it is suitable for normal CI. It is also a good default for application tests that need to exercise subscription behavior, send correlation IDs, and basic multi-channel routing.
For recovery tests, pass a VirtualRecoveryOptions instance through CanOpenOptions.NativeOptions and keep its VirtualFaultInjector. Calling InjectBusOff() publishes a bus-off status and exercises the selected CanOpenOptions.Recovery policy without hardware.
var injector = new VirtualFaultInjector();
await using var bus = await registry.OpenAsync(
"virtual://recovery?channelIndex=0",
new CanOpenOptions
{
Recovery = CanRecoveryOptions.ResetOnFault(restartDelay: TimeSpan.Zero),
NativeOptions = new VirtualRecoveryOptions { FaultInjector = injector }
},
CancellationToken.None);
injector.InjectBusOff();
License
This package is licensed under the MIT License.
| 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. |
-
net10.0
- CanHub.Abstractions (>= 1.0.1)
- CanHub.Core (>= 1.0.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.8)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.1 | 96 | 6/1/2026 |
| 1.0.0-preview.8 | 56 | 5/25/2026 |
| 1.0.0-preview.7 | 50 | 5/23/2026 |
| 1.0.0-preview.6 | 56 | 5/21/2026 |
| 1.0.0-preview.5 | 49 | 5/21/2026 |
| 1.0.0-preview.4 | 56 | 5/21/2026 |
| 1.0.0-preview.3 | 56 | 5/20/2026 |
| 1.0.0-preview.2 | 48 | 5/19/2026 |
| 1.0.0-preview.1 | 59 | 5/15/2026 |
In-process virtual CAN/CAN FD bus for testing and protocol development.