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
                    
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="CanHub.Adapter.Virtual" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CanHub.Adapter.Virtual" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="CanHub.Adapter.Virtual" />
                    
Project file
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 CanHub.Adapter.Virtual --version 1.0.1
                    
#r "nuget: CanHub.Adapter.Virtual, 1.0.1"
                    
#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 CanHub.Adapter.Virtual@1.0.1
                    
#: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=CanHub.Adapter.Virtual&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=CanHub.Adapter.Virtual&version=1.0.1
                    
Install as a Cake Tool

CanHub.Adapter.Virtual

简体中文

NuGet .NET 10 License: MIT

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 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.

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.