Skip to content

IIsoTpChannel Interface

A single ISO 15765-2 (ISO-TP) channel bound to one IsoTpEndpoint (TX/RX CAN-ID pair, plus addressing mode). Threading model per SRS FR-TP-016 / FR-RAW-020..023: all protocol state is owned by a single IProtocolActor mailbox, so callers may invoke SendAsync(ReadOnlyMemory<byte>, CancellationToken) concurrently from arbitrary threads and receive frames from arbitrary threads; internal state is never mutated from more than one place at a time.

public interface IIsoTpChannel : System.IDisposable

Implements IDisposable

Remarks

One channel = one PDU at a time on the wire: an outgoing multi-frame PDU (First-Frame + Consecutive-Frames) is completed (or aborted with an IsoTpException) before the next SendAsync(ReadOnlyMemory<byte>, CancellationToken) call is transmitted. This mirrors ISO 15765-2 §6.4's "one N-USData at a time" model; overlapping sends from different callers are serialized by the channel.

Received PDUs are delivered both as an event (DatagramReceived) and as an System.Collections.Generic.IAsyncEnumerable<> from ReceiveAllAsync(CancellationToken); a single ReceiveAsync(CancellationToken) call awaits the next one. Both surfaces share the same bounded buffer.

IDisposable.Dispose is thread-safe and idempotent (FR-RAW-021).

Properties

IIsoTpChannel.Endpoint Property

The endpoint this channel is bound to (TX/RX CAN-ID pair + addressing mode).

CanKit.Pro.IsoTp.IsoTpEndpoint Endpoint { get; }

Property Value

IsoTpEndpoint

IIsoTpChannel.Options Property

The channel options used at construction (immutable).

CanKit.Pro.IsoTp.IsoTpChannelOptions Options { get; }

Property Value

IsoTpChannelOptions

Methods

IIsoTpChannel.DiscardPendingPdus() Method

Drains every buffered inbox item — both completed PDUs and pending reassembly-abort faults enqueued by AbortRx — and returns how many were dropped. Also silently aborts any in-flight multi-frame reassembly on the actor so leftover consecutive frames cannot finish and enqueue a stale PDU after a higher-layer timeout/cancel (Bugbot 3596444314). Higher layers (e.g. UDS) call this after a cancelled/timed-out wait so a late peer PDU or a leftover abort fault cannot be consumed as the answer to a later request.

int DiscardPendingPdus();

Returns

Int32

IIsoTpChannel.ReceiveAllAsync(CancellationToken) Method

Enumerates every fully reassembled inbound PDU as it becomes available. The enumeration ends when the channel is disposed. A reassembly abort (N_Cr / CF sequence mismatch / SF·FF supersede) faults the enumerator with the same exception ReceiveAsync(CancellationToken) would throw. Cancel by passing a token via WithCancellation or by disposing the channel.

System.Collections.Generic.IAsyncEnumerable<byte[]> ReceiveAllAsync(System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

cancellationToken CancellationToken

Returns

IAsyncEnumerable<Byte[]>

IIsoTpChannel.ReceiveAsync(CancellationToken) Method

Awaits the next fully reassembled inbound PDU. Cancels via cancellationToken. Faults with IsoTpTimeoutException (NCr) or IsoTpException when an in-progress multi-frame reassembly is aborted (N_Cr, CF sequence mismatch, or a superseding SF/FF — including when the new FF is refused with FC(OVFLW); FR-TP-010), so a caller waiting for that PDU does not hang indefinitely.

System.Threading.Tasks.Task<byte[]> ReceiveAsync(System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

cancellationToken CancellationToken

Returns

Task<Byte[]>

IIsoTpChannel.SendAsync(ReadOnlyMemory<byte>, CancellationToken) Method

Sends pdu as one ISO-TP N-USData PDU. The returned task completes when the last frame of the PDU is TX-confirmed by the driver (SF) or when the peer has FC-cleared the entire multi-frame PDU and the last CF is confirmed (FF+CFs). It faults with an IsoTpException on protocol timeouts (FR-TP-010), an Overflow FC (FR-TP-012), exceeding WFTmax (FR-TP-011), or a driver rejection.

System.Threading.Tasks.Task SendAsync(System.ReadOnlyMemory<byte> pdu, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

pdu ReadOnlyMemory<Byte>

User data, 1..4095 bytes for classic CAN, or up to MaxFdFirstFrameLength for CAN-FD. Must not be empty.

cancellationToken CancellationToken

Cancels the returned task (standard .NET convention); a canceled send aborts the in-flight PDU. The channel keeps the one-PDU-at-a-time send gate until any already-submitted bus TX from that PDU completes, so the next call cannot interleave frames on the wire with the aborted transfer.

Returns

Task

Events

IIsoTpChannel.BackgroundExceptionOccurred Event

Raised when a background failure (reassembly abort, event-handler exception, subscription failure, actor loop exception) needs to be surfaced to the application. This is the documented channel for out-of-band errors (FR-RAW-023). Failures tied to a specific SendAsync(ReadOnlyMemory<byte>, CancellationToken) call are reported via that call's returned task; reassembly aborts are reported both here and by faulting a pending ReceiveAsync(CancellationToken) (FailTx analogue on the receive side).

event EventHandler<Exception>? BackgroundExceptionOccurred;

Event Type

EventHandler<Exception>

IIsoTpChannel.DatagramReceived Event

Raised (on a thread-pool thread) every time a full PDU is reassembled. The same PDU is enqueued for ReceiveAsync(CancellationToken)/ReceiveAllAsync(CancellationToken) before the event fires, so a handler that synchronously waits on those APIs — or on DiscardPendingPdus() — cannot deadlock the protocol actor. Handlers must be non-throwing; a throwing handler is caught and surfaced via BackgroundExceptionOccurred.

event EventHandler<IsoTpDatagramReceivedEventArgs>? DatagramReceived;

Event Type

EventHandler<IsoTpDatagramReceivedEventArgs>