Table of Contents

Class SubscribeConnection

Namespace
DuetAPIClient
Assembly
DuetAPIClient.dll

Connection class for subscribing to model updates

public sealed class SubscribeConnection : BaseConnection, IDisposable
Inheritance
SubscribeConnection
Implements
Inherited Members

Constructors

SubscribeConnection()

Creates a new connection in subscriber mode

public SubscribeConnection()

Properties

Channel

Code channel to receive messages from. If not set, only generic messages are forwarded (as in v3.3 and earlier)

public CodeChannel? Channel { get; }

Property Value

CodeChannel?

Remarks

This has no effect in Full mode

Filters

Filter expressions

public List<string> Filters { get; }

Property Value

List<string>
See Also

Mode

Mode of the subscription

public SubscriptionMode Mode { get; }

Property Value

SubscriptionMode

Methods

Connect(SubscriptionMode, IEnumerable<string>?, string?)

Establishes a connection to the given UNIX socket file

public void Connect(SubscriptionMode mode, IEnumerable<string>? filters = null, string? socketPath = null)

Parameters

mode SubscriptionMode

Subscription mode

filters IEnumerable<string>

Optional filter strings

socketPath string

Optional path to the DCS UNIX socket file

Exceptions

IncompatibleVersionException

API level is incompatible

IOException

Connection mode is unavailable

SocketException

Init message could not be processed

Connect(SubscriptionMode, CodeChannel?, IEnumerable<string>?, string?)

Establishes a connection to the given UNIX socket file

public void Connect(SubscriptionMode mode, CodeChannel? channel, IEnumerable<string>? filters = null, string? socketPath = null)

Parameters

mode SubscriptionMode

Subscription mode

channel CodeChannel?

Optional code channel to receive messages from (not applicable in Full mode)

filters IEnumerable<string>

Optional filter strings

socketPath string

Optional path to the DCS UNIX socket file

Exceptions

IncompatibleVersionException

API level is incompatible

IOException

Connection mode is unavailable

SocketException

Init message could not be processed

ConnectAsync(SubscriptionMode, IEnumerable<string>?, string?, CancellationToken)

Establishes a connection to the given UNIX socket file asynchronously

public Task ConnectAsync(SubscriptionMode mode, IEnumerable<string>? filters = null, string? socketPath = null, CancellationToken cancellationToken = default)

Parameters

mode SubscriptionMode

Subscription mode

filters IEnumerable<string>

Optional filter strings

socketPath string

Optional path to the DCS UNIX socket file

cancellationToken CancellationToken

Optional cancellation token

Returns

Task

Asynchronous task

Exceptions

IncompatibleVersionException

API level is incompatible

IOException

Connection mode is unavailable

OperationCanceledException

Operation has been cancelled

SocketException

Init message could not be processed

ConnectAsync(SubscriptionMode, CodeChannel?, IEnumerable<string>?, string?, CancellationToken)

Establishes a connection to the given UNIX socket file asynchronously

public Task ConnectAsync(SubscriptionMode mode, CodeChannel? channel, IEnumerable<string>? filters = null, string? socketPath = null, CancellationToken cancellationToken = default)

Parameters

mode SubscriptionMode

Subscription mode

channel CodeChannel?

Optional code channel to receive messages from (not applicable in Full mode)

filters IEnumerable<string>

Optional filter strings

socketPath string

Optional path to the DCS UNIX socket file

cancellationToken CancellationToken

Optional cancellation token

Returns

Task

Asynchronous task

Exceptions

IncompatibleVersionException

API level is incompatible

IOException

Connection mode is unavailable

OperationCanceledException

Operation has been cancelled

SocketException

Init message could not be processed

GetObjectModel()

Retrieves the full object model of the machine. In subscription mode this is the first command that has to be called once a connection has been established.

public ObjectModel GetObjectModel()

Returns

ObjectModel

The current machine model

Exceptions

SocketException

Receipt could not be acknowledged

See Also

GetObjectModelAsync(CancellationToken)

Retrieves the full object model of the machine asynchronously. In subscription mode this is the first command that has to be called once a connection has been established.

public Task<ObjectModel> GetObjectModelAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Optional cancellation token

Returns

Task<ObjectModel>

The current machine model

Exceptions

OperationCanceledException

Operation has been cancelled

SocketException

Receipt could not be acknowledged

See Also

GetObjectModelPatch()

Receive a (partial) object model update. If the subscription mode is set to Patch, new update patches of the object model need to be applied manually. This method is intended to receive such fragments.

public JsonDocument GetObjectModelPatch()

Returns

JsonDocument

The partial update JSON

Exceptions

SocketException

Receipt could not be acknowledged

See Also

GetObjectModelPatchAsync(CancellationToken)

Receive a (partial) object model update asynchronously. If the subscription mode is set to Patch, new update patches of the object model need to be applied manually. This method is intended to receive such fragments.

public Task<JsonDocument> GetObjectModelPatchAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

An optional cancellation token

Returns

Task<JsonDocument>

The partial update JSON

Exceptions

OperationCanceledException

Operation has been cancelled

SocketException

Receipt could not be acknowledged

See Also

GetSerializedObjectModel()

Optimized method to query the object model UTF-8 JSON in any mode. May be used to get machine model patches as well.

public MemoryStream GetSerializedObjectModel()

Returns

MemoryStream

Machine model JSON

Exceptions

SocketException

Receipt could not be acknowledged

See Also

GetSerializedObjectModelAsync(CancellationToken)

Optimized method to query the object model UTF-8 JSON in any mode asynchronously. May be used to get machine model patches as well.

public Task<MemoryStream> GetSerializedObjectModelAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Optional cancellation token

Returns

Task<MemoryStream>

Machine model JSON

Exceptions

OperationCanceledException

Operation has been cancelled

SocketException

Receipt could not be acknowledged

See Also

See Also