Skip to content

LssBitRateDetection Class

Automatic bit-rate detection in listen-only mode (CiA 801 §5.2.3, Figure 1): the procedure behind table 0 index 9 of CiA 305 (AutomaticIndex), FR-CO-050.

public static class LssBitRateDetection

Inheritance Object → LssBitRateDetection

Remarks

For each candidate the caller's factory opens the controller at that rate, accepting every identifier and in ListenOnly, so the search acknowledges nothing and transmits no error frame (§5.2.1). The detection then waits for the first of: a received frame, which the controller only delivers when the rate is right, so the candidate is Detected; the number of error frames ErrorFramesToReject names, which makes it Rejected; or the end of the listen window. A candidate whose window ends with the controller no longer error-active is rejected as well, since some adapters move ICanBus.BusState without raising ICanBus.ErrorFrameReceived; otherwise it is Inconclusive. The bus of each probe is disposed before the next is opened.

The method needs traffic (§6): at least one frame has to be on the bus while the correct candidate is open. A CANopen manager that wants its devices to find the rate produces it with its heartbeat, with SYNC, or with SDO reads of 1000h, 1001h or 1018h; the node's heartbeat and SYNC producers do that here. The number of frames the search consumes depends on how many candidates are tried before the right one and on the time the adapter needs to close and reopen between two candidates (Figure 2).

What CiA 801 describes and this type does not do: measuring the time of a single dominant bit (§5.2.2) needs a timer on the receive line, which no adapter exposes; the external AND/OR gate for controllers without a listen-only mode (§5.2.4) is hardware; and the default fallback bit rate (§5.1) is the approach the report rejects.

A fault the bus reports (ICanBus.FaultOccurred) ends the detection with that exception, after the bus is disposed: a dead adapter does not look like a silent bus.

Methods

LssBitRateDetection.DetectAsync(Func<int,ICanBus>, LssBitRateDetectionOptions, CancellationToken) Method

Finds the bit rate of the bus by listening at each candidate in turn.

public static System.Threading.Tasks.Task<CanKit.Pro.CANopen.Lss.LssBitRateDetectionResult> DetectAsync(System.Func<int,CanKit.Abstractions.API.Can.ICanBus> openListenOnly, CanKit.Pro.CANopen.Lss.LssBitRateDetectionOptions? options=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

openListenOnly Func<Int32,ICanBus>

Opens the controller at the given bit rate in bits per second, in ListenOnly, accepting every identifier, with error reporting enabled where the adapter offers it. Called once per probe; the bus it returns is disposed when the probe ends. With CanKit.Core that is rate => CanBus.Open(endpoint, cfg => cfg.Baud(rate).SetWorkMode(ChannelWorkMode.ListenOnly).EnableErrorInfo()).

options LssBitRateDetectionOptions

The candidates, the window, and the thresholds; null is a fresh LssBitRateDetectionOptions.

cancellationToken CancellationToken

Ends the detection with OperationCanceledException; the bus of the probe in progress is disposed.

Returns

Task<LssBitRateDetectionResult>

Exceptions

InvalidOperationException
The factory returned null, a bus whose work mode is not listen-only, or whose adapter does not apply listen-only, while RequireListenOnly holds, or a bus whose nominal bit rate names a rate other than the candidate.