CanKit.Pro.IsoTp 1.4.0

dotnet add package CanKit.Pro.IsoTp --version 1.4.0
                    
NuGet\Install-Package CanKit.Pro.IsoTp -Version 1.4.0
                    
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="CanKit.Pro.IsoTp" Version="1.4.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CanKit.Pro.IsoTp" Version="1.4.0" />
                    
Directory.Packages.props
<PackageReference Include="CanKit.Pro.IsoTp" />
                    
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 CanKit.Pro.IsoTp --version 1.4.0
                    
#r "nuget: CanKit.Pro.IsoTp, 1.4.0"
                    
#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 CanKit.Pro.IsoTp@1.4.0
                    
#: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=CanKit.Pro.IsoTp&version=1.4.0
                    
Install as a Cake Addin
#tool nuget:?package=CanKit.Pro.IsoTp&version=1.4.0
                    
Install as a Cake Tool

CanKit.Pro.IsoTp

ISO 15765-2 (ISO-TP) implementation for CanKit (CanKit.Pro). The package now ships two halves:

  1. Codec — deterministic, side-effect-free builders and parsers for the four ISO-TP PCI frame types (Single Frame, First Frame, Consecutive Frame, Flow Control) on classic CAN and CAN-FD.
  2. Runtime (IIsoTpChannel) — an actor-driven channel that composes on top of the CanKit.Pro L2 services (CanKit.Pro.RawCan demux + SendConfirmedAsync, CanKit.Pro.Actor, CanKit.Pro.Reliability deadlines). Segments outbound PDUs into SF/FF/CFs, honors peer Flow Control (BS/STmin/Wait/ Overflow) and enforces N_As/N_Bs/N_Cr timers, reassembles inbound PDUs (SN-checked), and delivers them via ReceiveAsync / ReceiveAllAsync / DatagramReceived.

Status: 1.3.0 is the first stable release: from 1.3.0 on the public API follows SemVer, so a breaking change costs a major version. 1.0.0 – 1.2.3 were published as stable before the API had been reviewed against the specifications; they are unlisted and deprecated on nuget.org and should not be used. See Versioning. CAN-FD long-payload cases still get the least coverage of the two halves.

What is validated, and what is not

Validated: The frame codec (unit and property tests), and the channel over CanKit.Adapter.Virtual, directly or through a controllable bus double: segmentation, Flow Control (BS, STmin, Wait, Overflow), the N_As/N_Bs/N_Cr timers, reassembly, functional addressing and CAN-FD, by the test suite in tests/CanKit.Pro.Tests. STmin pacing is tested on a clock the test drives, so the interval is checked exactly and no real elapsed time is measured.

Not validated: Conformance to ISO 15765-2 as a tester or a foreign ISO-TP stack would judge it, and STmin spacing in real time, on any host or adapter, where it carries scheduling and adapter latency. Nothing in this package has run against real CAN hardware, a conformance tester or a third-party implementation: the test project references CanKit.Adapter.Virtual and no hardware adapter.

Scope

  • IsoTpFrameCodec — bounds-safe PCI parser, BuildSingleFrame / BuildFirstFrame / BuildConsecutiveFrame / BuildFlowControl, correct classic-CAN vs CAN-FD DLC/capacity, correct First-Frame length encoding including the 32-bit CAN-FD escape form (lengths > 4095), and bounds-checked PCI parsing that never throws IndexOutOfRangeException on short frames.
  • IsoTpFrameCodec.EncodeStMin / DecodeStMin — full ISO 15765-2 STmin range including the commonly-used 0 ms and 1 ms values (Encode) and the reserved bands 0x80..0xF0 and 0xFA..0xFF which decode to 127 ms (0x7F) instead of throwing.
  • IsoTpFrameCodec.NextConsecutiveSequenceNumber — Consecutive-Frame sequence numbering that starts at 1 after the First Frame and wraps 0..15.
  • Pci / PciType / FlowStatus — parsed Protocol-Control-Information view.
  • IsoTpEndpoint / IsoTpAddressingMode — minimal addressing value type covering Normal, NormalFixed, Extended and Mixed addressing for codec purposes only.

Runtime — IIsoTpChannel

  • IsoTp.Open(ICanBus, IsoTpEndpoint, IsoTpChannelOptions?) — opens a channel that owns a private CanBusService around the supplied bus.
  • IsoTp.Open(ICanBusService, IsoTpEndpoint, IsoTpChannelOptions?, leaveOpen) — opens a channel on an existing service (allows multiple ISO-TP endpoints to multiplex over the same physical bus, SRS FR-TP-018).
  • SendAsync(ReadOnlyMemory<byte>, CancellationToken) — sends one PDU; task completes on TX-confirm of the last frame. SendWithTransmitStampAsync returns IsoTpTransmitStamps, bracketing the driver call for the last frame as the bus service reports it from inside its send lock: just before the handoff (a caller's cutoff for what can still be a response to this PDU — a peer answers only a complete request) and no later than the driver accepted it (where a response deadline starts); the two are not interchangeable (#146). Faults with IsoTpTimeoutException, IsoTpOverflowException, IsoTpWaitFrameLimitExceededException, or IsoTpSendRejectedException on the corresponding ISO 15765-2 error cases. A reception aborted by a Consecutive Frame with the wrong sequence number faults ReceiveAsync and is reported with IsoTpWrongSequenceNumberException; one aborted by a Single Frame or a new First Frame arriving in its place with IsoTpUnexpectedPduException (both derive from IsoTpException and keep its error code).
  • ReceiveAsync / ReceiveAllAsync — two surfaces onto the same bounded, drop-oldest PDU inbox (bounded to IsoTpChannelOptions.ReceiveBufferCapacity, default 64), in arrival order. The drop is silent — no BackgroundExceptionOccurred, no counter — and takes a queued reassembly-abort fault as readily as a PDU, so a channel nobody reads from loses PDUs without a trace once the inbox is full. What is queued before the channel is disposed, or before its bus service is lost, is still delivered; an empty inbox then ends a receive with InvalidOperationException (disposed) or with ObjectDisposedException / the subscription's own failure (service lost), the latter also raised once through BackgroundExceptionOccurred. DatagramReceived is not one of them: each completed PDU is raised on its own thread-pool work item, so handlers may run concurrently and out of order; nothing is raised for a frame handled after Dispose has begun, but a handler already queued may still run. ReceiveWithArrivalAsync returns an IsoTpReceivedPdu stamped with the arrival of its last frame and of its first (FirstFrameArrivalTimestamp), because an application deadline such as UDS P2 ends with the first frame; GetReceptionsInProgress reports the multi-frame receptions that have begun but not completed, oldest first, each as an IsoTpReceptionInProgress — that stamp, the announced length and the First Frame's data bytes, so the application layer can tell whose response it is. A record is published when the First Frame is taken from the subscription, before the channel's actor has processed it (several can be pending while the actor is behind), and withdrawn on its outcome or if the actor refuses the frame; the call itself drains what the demux has buffered first, so the answer does not wait for the reader task's scheduling either. A caller waiting on one re-checks rather than waiting unboundedly. DiscardPendingPdus drains the demux buffer the same way before clearing, so a frame buffered at discard time is part of what it drops. SettleAsync drains it the same way and completes once the actor has taken everything queued so far, without dropping anything: for a decision taken at a deadline, what the inbox does not hold after it did not arrive before the call — a Single Frame stamped in time can otherwise still be on its way when the deadline fires. A CancellationToken ends the wait, not the settling: what the demux buffered has been handed to the actor by then. DiscardPendingPdus(long) drops what arrived before the caller's own stamp rather than before now, so a caller that reads the inbox after taking the stamp and discards after reading has seen everything it drops, and a frame from between the read and the discard is kept.
  • Timings: IsoTpChannelOptions.NAs (TX-confirm), NAr (confirm of the Flow Control sent while receiving), NBs (peer-FC wait), NCr (next CF wait) and WftMax (max consecutive Wait FCs) are configurable; defaults are the standard's 1000 ms each, and 10 (see item 9 below).
  • Frame size: IsoTpChannelOptions.TxDl sets the CAN FD TX_DL — 8, 12, 16, 20, 24, 32, 48 or 64 (default), checked when the channel is created. StrictReceive (default off) makes the channel ignore a Single Frame whose CAN frame length does not fit its form (item 11 below).
  • Reception limits: a First Frame announcing more than MaxReceivePduLength (default 65 535 bytes; classic CAN is bounded at 4095 by the codec anyway) is answered with FC(OVFLW) and nothing is allocated for it, so a CAN-FD escape First Frame cannot make the process reserve the ~2 GB it may announce. A Consecutive Frame whose CAN_DL is not the First Frame's, unless it is the last one, is ignored as ISO 15765-2:2024 §9.5.3/§9.6.4.1 require — it is not copied short. A First Frame announcing no more than a Single Frame of the same CAN_DL could carry is ignored too (§9.6.3.2): no Flow Control, no reassembly (#56).
  • Flow parameters: the sender takes BS and STmin from every FC(CTS) of a transfer, as ISO 15765-2:2024 §9.6.5.6 requires of a client sending to a server that may change them between blocks. A reserved STmin makes it use 127 ms for the rest of that transfer (§9.6.5.5). The receiver side advertises the same LocalBlockSize/LocalStMin in every FC, as a client receiving must.
  • Echoes: a channel receives on RxCanId and transmits on TxCanId, so on an echo-capable bus its own frames never match its filter and host echoes are kept — two reciprocal channels in one process are peers. The one exception is an endpoint with TxCanId == RxCanId and no address-extension byte telling the directions apart (Normal addressing, or Mixed with its one shared byte): there the host echo flag is the only thing telling the channel's frame from the peer's, and host echoes are withheld (#56). Extended addressing on one identifier keeps them, the source and target bytes doing the telling.
  • BackgroundExceptionOccurred is raised on the thread pool, never on the channel's actor, one report at a time in the order they were made, and each handler is called on its own (#356, #381). A reassembly abort has faulted the inbox before its report goes out, so a handler may call ReceiveAsync, DiscardPendingPdus or SendAsync, or dispose the channel, without deadlocking the actor. Called on the actor itself -- other work on an injected actor -- DiscardPendingPdus runs its clear inline instead of waiting on the loop it is on (#56).

Timing accuracy — STmin pacing (NFR-003)

The sender paces Consecutive Frames by the peer's advertised STmin using the L2 DeadlineScheduler (actor-driven, event-based — no busy wait). On general-purpose operating systems the effective CF spacing is STmin + OS scheduling latency, with no real-time guarantee, and nothing in this repository measures how large that latency is on any host. Sub-millisecond STmin values (0xF1..0xF9, 100–900 µs) are honored as-is but bottom out at the platform timer resolution.

What the suite does verify is the logic, not the wall clock: tests/CanKit.Pro.Tests/TestCases/IsoTp/IsoTpStminTimingTests.cs advances a clock the test drives and checks that the sender releases exactly one Consecutive Frame per STmin interval. The requirement NFR-003 asks for a documented accuracy (for example ±1 ms); that figure is a target, not a measured result.

Functional (1:N) addressing — IsoTpFunctionalClient (FR-TP-019)

Per ISO 15765-2:2024 §8.3.2.4 / ISO 14229-1 §7.7.1, a tester can broadcast a request to all ECUs on the bus using a shared functional CAN identifier and collect Single-Frame responses from multiple ECUs.

// Open a functional client (owns its own CanBusService).
using var client = IsoTp.OpenFunctional(
    bus,
    functionalTxCanId:          0x7DF,
    responseRxCanIdRangeStart:  0x7E8,
    responseRxCanIdRangeEnd:    0x7EF);

// Broadcast a UDS DiagnosticSessionControl(DefaultSession) request and collect all replies
// received within 25 ms.
IReadOnlyList<IsoTpFunctionalResponse> responses = await client.SendAndCollectAsync(
    pdu: new byte[] { 0x10, 0x01 },
    window: TimeSpan.FromMilliseconds(25));

foreach (var r in responses)
    Console.WriteLine($"ECU 0x{r.SourceCanId:X3}: {BitConverter.ToString(r.Data)}");
  • IsoTp.OpenFunctional(ICanBus, …) — client owns a private CanBusService.
  • IsoTp.OpenFunctional(ICanBusService, …, leaveOpen) — shares an existing service with physical IIsoTpChannel instances (disjoint ID ranges required, FR-TP-018).
  • SF-only send (ISO 15765-2:2024 §8.3.2.4 restriction): a PDU that exceeds the Single-Frame capacity for the configured frame kind faults the task with InvalidOperationException.
  • SF-only collection: First-Frame responses (which would require per-ECU physical Flow-Control addresses) are silently dropped; Single-Frame responses from all ECUs within the range are collected in arrival order.
  • IsoTpFunctionalOptions configures IsExtendedCanId, UseCanFd, TxDl (CAN FD TX_DL, same values and default 64 as the channel's, checked when the client is opened), UsePadding, PaddingByte, NAs (TX-confirm timeout) and StrictReceive (default off: the channel's Single Frame length checks of item 11, applied to the collected responses).
  • When the request went out: SendWithTransmitStampAsync and SendAndCollectWithTransmitStampAsync return IsoTpTransmitStamps — the instant the frame was handed to the driver and the instant it was transmitted — for a caller that keeps a deadline from the transmission. A response that arrived before the handoff answers something else (the subscription is made before the send, and another sender may hold the service's transmit lock in between) and is left out of the collection.
  • Listening across collections: CollectResponsesAsync subscribes per call, so a response that arrives between two calls — or between a SendAsync and the first call — is missed. client.Listen() subscribes once and returns an IsoTpFunctionalListener whose CollectAsync(window) collects from that standing subscription: obtained before the send, it hears the fastest reply, and what arrives between two collections is buffered for the next. Dispose it to end the subscription.

ISO 15765-2:2024 — how the channel reads it

Checked against ISO 15765-2:2024 (4th edition), which replaced the 2016 edition (#353). The 2024 text moves the whole protocol into clause 9 and renames the timers to t_TL_As, t_TL_Ar, t_TL_Bs, t_TL_Cr and the results to CTL_*; this package keeps the familiar NAs/NAr/NBs/NCr names, and its clause numbers refer to the 2024 edition.

  1. N_Ar. The Flow Control a receiving channel sends has its own confirmation timer, NAr (default 1000 ms). If it expires, or the driver fails the frame, the reception is aborted and ReceiveAsync faults with IsoTpTimeoutException (IsoTpTimer.NAr) or IsoTpException (§9.8.1 Table 22, §9.8.2 Table 23: CTL_TIMEOUT_A). A Consecutive Frame that arrives before the confirmation shows the peer has the Flow Control and ends N_Ar as well. FC(OVFLW) starts no reception and is sent without it.
  2. Where N_Cr starts. At the Flow Control's confirmation, or at a Consecutive Frame that arrives first (Table 22). Until then only N_Ar runs.
  3. Reserved FlowStatus. A Flow Control with a FlowStatus of 3..F aborts the send at once with IsoTpInvalidFlowStatusException when the sender is waiting for a Flow Control (§9.6.5.2, CTL_INVALID_FS). Received at any other time it is ignored (§9.8.3, Table 24). TryParsePci returns such a Flow Control with the raw value in Pci.FlowStatus.
  4. First Frames too large to take. Any First Frame announcing more than MaxReceivePduLength — up to the CAN FD escape form's 2³² − 1 bytes — is answered with FC(OVFLW) and nothing is allocated (§9.6.3.2). Pci.LongLength carries an escape FF_DL above int.MaxValue.
  5. STmin rounding. EncodeStMin rounds a value between two codes up: LocalStMin = 190 µs advertises 200 µs, 999 µs advertises 1 ms and 1.4 ms advertises 2 ms; above 127 ms it is capped at 127 ms. The standard defines only the codes (§9.6.5.4, Table 21); rounding up keeps the receiver from advertising less separation than it was configured for.
  6. TX_DL and BRS. With UseCanFd the sender uses TxDl (default 64), one of the values §9.5.1 (Table 7) permits; any other value fails channel creation. A classic channel always uses 8. Receiving adapts to any TX_DL the peer uses (§9.5.2, RX_DL from the First Frame). The bit-rate switch is a bus/adapter setting outside ISO 15765-2; the channel does not set BRS.
  7. Classic and CAN FD frames on one link. A reception started with CAN FD frames is neither continued nor ended by a classic frame, and the other way round (§9.5.2); such a frame is ignored while the reception runs.
  8. STmin before the first Consecutive Frame. After every FC(CTS) the sender waits STmin before the first Consecutive Frame, not only between Consecutive Frames. §9.6.5.4 only requires the gap between two Consecutive Frames, so this is the conservative reading and costs at most one STmin per block.
  9. WFTmax. §9.7 makes WFTmax a receiver parameter (how many FC(WAIT) a receiver may send). The channel never sends FC(WAIT) and uses WftMax (default 10) as a sender-side guard: more consecutive Waits than that abort the send with IsoTpWaitFrameLimitExceededException. A conforming peer that needs more Waits is cut off by it; raise WftMax for such a peer. The default of 10 is this library's choice — the standard gives none — and bounds the wait at about ten times NBs.
  10. Escape Single Frames. A received CAN FD Single Frame in the escape form (0x00 LEN) is ignored unless its CAN_DL is above 8 and its SF_DL needs that CAN_DL, i.e. would not have fit the next smaller one (§9.6.2.2, Table 14). Earlier versions took such frames.
  11. Single Frame length checks on receive. §9.6.2.2 asks a receiver to ignore a Single Frame whose CAN_DL does not fit its form: on a padded link one whose CAN_DL is not 8; on an unpadded (optimised) link one up to 8 bytes whose CAN_DL is not SF_DL plus the PCI and address-extension bytes (Table 13); and one longer than 8 bytes in the short PCI form. The channel does these checks only with StrictReceive; by default it takes such frames, as peers that get them wrong are common. On an unpadded link this also drops a padded 8-byte frame whose SF_DL is shorter. The functional client has the same option for the responses it collects. The escape-form bounds of item 10 apply always.

Non-scope (yet)

  • Multi-frame (FF/CF) response reassembly in functional sessions (requires caller to supply a per-ECU physical TX address for Flow-Control replies).
  • No vendor-SDK references, ever.
  • The legacy CanKit.Transport.IsoTp prototype (and its Abstractions API/Transport surface plus the PCAN native ISO-TP register) has been removed; this package is the sole ISO-TP implementation path.

Fixes over the prototype (see review §1.1)

The codec is the specification-compliant replacement for the removed legacy prototype codec and deliberately avoids the following defects:

  1. Inverted CAN vs CAN-FD frame kind — this codec is agnostic; it returns the frame payload bytes plus the intended CAN kind, callers construct the CAN frame with the correct kind (FR-TP-003).
  2. Flow-Control frames now carry PCI type 0x3 (not the First-Frame nibble) (FR-TP-004).
  3. Padding is applied after the BS/STmin bytes and never overwrites them (FR-TP-004).
  4. First-Frame length high-nibble is composed with correct operator precedence (((data[0] & 0x0F) << 8) | data[1]), so lengths in [256, 4095] round-trip (FR-TP-005).
  5. EncodeStMin accepts the commonly-used 0 ms and 1 ms values (FR-TP-006).
  6. DecodeStMin maps the reserved raw values 0x80..0xF0 and 0xFA..0xFF to 127 ms (0x7F) per ISO 15765-2:2024 §9.6.5.5 instead of throwing (FR-TP-007, FR-RAW-052).
  7. Consecutive-Frame sequence numbers start at 1 and wrap 0..15 (FR-TP-008).
  8. TryParsePci is bounds-safe and never throws IndexOutOfRangeException, even for a 1-byte frame or a truncated Flow-Control frame (FR-TP-007).
  9. Classic-CAN single frames are always ≤ 8 bytes (FR-TP-015).
  10. BuildSingleFrame rejects a zero-length payload at build time: ISO 15765-2 does not define a Single Frame with SF_DL == 0, so producing such a frame would yield bytes no conformant peer could parse (bugbot 3594958440).
  11. TryParsePci requires an isCanFd argument so the Single-Frame escape header (0x00 LEN …) and the First-Frame escape header (0x10 0x00 LEN[4] …) are only accepted on CAN-FD frames; on classic CAN those bit-patterns are invalid and are rejected instead of being mis-parsed as escape headers (bugbot 3594958440 / 3594958445).

Status: codec plus runtime channel, both shipped. See the note at the top of this file on the withdrawn 1.0.0 – 1.2.3 releases.

Install

dotnet add package CanKit.Pro.IsoTp

# plus a CanKit adapter for the hardware you actually talk to, e.g.
dotnet add package CanKit.Adapter.Virtual   # loopback, no hardware

Dependencies: CanKit.Abstractions, CanKit.Pro.Actor, CanKit.Pro.RawCan, CanKit.Pro.Reliability.

Part of CanKit.Pro — higher CAN protocol layers built on top of CanKit, which is consumed as a NuGet package rather than forked.

License

MIT — see LICENSE. CanKit itself is a separate project licensed under Apache-2.0; see THIRD-PARTY-NOTICES.md.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on CanKit.Pro.IsoTp:

Package Downloads
CanKit.Pro.Uds

Unified Diagnostic Services (ISO 14229-1) client for CanKit.Pro. Provides an async IUdsClient over IIsoTpChannel with the implemented service set (0x10 DiagnosticSessionControl, 0x11 ECUReset, 0x22 ReadDataByIdentifier, 0x27 SecurityAccess, 0x2E WriteDataByIdentifier, 0x31 RoutineControl, 0x34 RequestDownload, 0x35 RequestUpload, 0x36 TransferData, 0x37 RequestTransferExit, 0x3E TesterPresent), P2/P2* timing, NRC 0x78 responsePending handling and structured negative-response reporting.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.4.0 1,261 11/16/2026
1.3.0 6,836 9/30/2026