Skip to content

CanOpenDiscovery Class

Finds the CANopen nodes on a bus (#131 decision 3; FR-CO-033, FR-CO-034). Listening is the default; scanning is a separate call, made only when the caller asks for it.

public static class CanOpenDiscovery

Inheritance Object → CanOpenDiscovery

Remarks

ListenAsync(ICanBus, Nullable<TimeSpan>, CancellationToken) opens no node and transmits nothing. It collects heartbeats and boot-ups for a window the caller chooses (DefaultListenWindow if not). One of the two is enough for a node to count as present.

ScanAsync(ICanOpenNode, IEnumerable<byte>, CancellationToken) uses a node the caller has opened. It sends an SDO upload of 1000h:00 to every node-id 1..127 except the client's own and the ones the caller passes, typically those a listen already found. That is the only request it sends: the pair is one the peer-SDO gate allows without a peer file, and with a peer file bound only if the file lists it. A node that stays silent also receives the SDO client's usual timeout abort (0504 0000h), which lets a node that answers late drop its half-open transfer.

Properties

CanOpenDiscovery.DefaultListenWindow Property

The listen window when the caller does not choose one: 2 seconds.

public static System.TimeSpan DefaultListenWindow { get; }

Property Value

TimeSpan

Methods

CanOpenDiscovery.ListenAsync(ICanBus, Nullable<TimeSpan>, CancellationToken) Method

Listens on bus for heartbeats and boot-ups and returns the nodes heard, ordered by node-id. Opens no CANopen node and transmits nothing.

public static System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyList<CanKit.Pro.CANopen.CanOpenDiscoveredNode>> ListenAsync(CanKit.Abstractions.API.Can.ICanBus bus, System.Nullable<System.TimeSpan> window=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

bus ICanBus

The bus. It is not disposed.

window Nullable<TimeSpan>

How long to listen. Any positive duration up to Int32.MaxValue milliseconds; null is DefaultListenWindow.

cancellationToken CancellationToken

Ends the listen early with OperationCanceledException.

Returns

Task<IReadOnlyList<CanOpenDiscoveredNode>>

Exceptions

ObjectDisposedException
The service ended the subscription before the window closed. What was heard until then is not returned as a complete listen.

CanOpenDiscovery.ListenAsync(ICanBusService, Nullable<TimeSpan>, CancellationToken) Method

Listens on an existing service, shared with other protocols on the same bus (FR-CO-012). The service is not disposed. Otherwise as ListenAsync(ICanBus, Nullable<TimeSpan>, CancellationToken).

public static System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyList<CanKit.Pro.CANopen.CanOpenDiscoveredNode>> ListenAsync(CanKit.Pro.RawCan.ICanBusService service, System.Nullable<System.TimeSpan> window=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

service ICanBusService

window Nullable<TimeSpan>

cancellationToken CancellationToken

Returns

Task<IReadOnlyList<CanOpenDiscoveredNode>>

CanOpenDiscovery.ScanAsync(ICanOpenNode, IEnumerable<byte>, CancellationToken) Method

Sends an SDO upload of 1000h:00 through client to each node-id 1..127 other than NodeId and skipNodeIds, and returns the nodes that answered, ordered by node-id.

public static System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyList<CanKit.Pro.CANopen.CanOpenDiscoveredNode>> ScanAsync(CanKit.Pro.CANopen.ICanOpenNode client, System.Collections.Generic.IEnumerable<byte>? skipNodeIds=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

client ICanOpenNode

An opened node whose SDO client does the reads.

skipNodeIds IEnumerable<Byte>

Node-ids not to ask, typically the result of ListenAsync(ICanBus, Nullable<TimeSpan>, CancellationToken). May be null.

cancellationToken CancellationToken

Cancels the outstanding requests.

Returns

Task<IReadOnlyList<CanOpenDiscoveredNode>>

Remarks

A node counts as present when it answers: with the value, which lands in DeviceType, with an SDO abort (Peer), or with a response the client aborts as malformed. The client's own timeout after SdoTimeout is absence.

No request goes out for a node-id whose bound peer description does not list 1000h:00 (PeerSdoAccessException), nor for one the client already has an SDO transfer with. Neither is reported, since nothing was asked. The requests to the different node-ids run concurrently. A failure that is none of these, such as a transport fault, ends the scan with that exception.