Table of Contents

Class InterceptConnection

Namespace
DuetAPIClient
Assembly
DuetAPIClient.dll

Connection class for intercepting G/M/T-codes from the control server

public sealed class InterceptConnection : BaseCommandConnection, IDisposable
Inheritance
InterceptConnection
Implements
Inherited Members

Constructors

InterceptConnection()

Creates a new connection in intercepting mode

public InterceptConnection()

Properties

AutoEvaluateExpressions

Automatically evaluate expression parameters to their final values before sending it over to the client. This requires AutoFlush to be true and happens when the remaining codes have been processed.

public bool AutoEvaluateExpressions { get; set; }

Property Value

bool

AutoFlush

Automatically flush the code channel before notifying the client in case a code filter is specified

public bool AutoFlush { get; set; }

Property Value

bool

Remarks

This option makes extra Flush calls in the interceptor implementation obsolete. It is highly recommended to enable this in order to avoid potential deadlocks when dealing with macros! This option is only used if at least one filter is used

Channels

List of input channels where codes may be intercepted. If the list is empty, all available channels are used

public List<CodeChannel> Channels { get; set; }

Property Value

List<CodeChannel>

Filters

List of G/M/T-codes to filter or Q0 for comments

public List<string> Filters { get; set; }

Property Value

List<string>

Remarks

This may only specify the code type and major/minor number (e.g. G1)

Mode

Mode of the interceptor

public InterceptionMode Mode { get; }

Property Value

InterceptionMode

PriortyCodes

Defines if priority codes may be intercepted (e.g. M122 or M999)

public bool PriortyCodes { get; }

Property Value

bool
See Also

Methods

CancelCode()

Instruct the control server to cancel the last received code (in intercepting mode)

public void CancelCode()

Exceptions

SocketException

Command could not be processed

See Also

CancelCodeAsync(CancellationToken)

Instruct the control server to cancel the last received code (in intercepting mode) asynchronously

public ValueTask CancelCodeAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Optional cancellation token

Returns

ValueTask

Asynchronous task

Exceptions

OperationCanceledException

Operation has been cancelled

SocketException

Command could not be processed

See Also

Connect(InterceptionMode, IEnumerable<CodeChannel>?, IEnumerable<string>?, bool, string?)

Establishes a connection to the given UNIX socket file

public void Connect(InterceptionMode mode, IEnumerable<CodeChannel>? channels = null, IEnumerable<string>? filters = null, bool priorityCodes = false, string? socketPath = null)

Parameters

mode InterceptionMode

Interception mode

channels IEnumerable<CodeChannel>

List of input channels where codes may be intercepted or null for all available channels

filters IEnumerable<string>

Optional list of codes that may be intercepted

priorityCodes bool

Define if priority codes may be intercepted

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(InterceptionMode, IEnumerable<CodeChannel>?, IEnumerable<string>?, bool, string?, CancellationToken)

Establishes a connection to the given UNIX socket file asynchronously

public Task ConnectAsync(InterceptionMode mode, IEnumerable<CodeChannel>? channels = null, IEnumerable<string>? filters = null, bool priorityCodes = false, string? socketPath = null, CancellationToken cancellationToken = default)

Parameters

mode InterceptionMode

Interception mode

channels IEnumerable<CodeChannel>

List of input channels where codes may be intercepted or null for all available channels

filters IEnumerable<string>

Optional list of codes that may be intercepted

priorityCodes bool

Define if priority codes may be intercepted

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

Flush()

When intercepting a code wait for all previous codes of the given channel to finish

public bool Flush()

Returns

bool

True if all pending codes could be flushed

Exceptions

InvalidOperationException

Requested code channel is disabled

SocketException

Command could not be processed

See Also

FlushAsync(CancellationToken)

When intercepting a code wait for all previous codes of the given channel to finish asynchronously

public Task<bool> FlushAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Optional cancellation token

Returns

Task<bool>

True if all pending codes could be flushed

Exceptions

InvalidOperationException

Requested code channel is disabled

SocketException

Command could not be processed

See Also

IgnoreCode()

Instruct the control server to ignore the last received code (in intercepting mode)

public void IgnoreCode()

Exceptions

SocketException

Command could not be processed

See Also

IgnoreCodeAsync(CancellationToken)

Instruct the control server to ignore the last received code (in intercepting mode) asynchronously

public ValueTask IgnoreCodeAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Optional cancellation token

Returns

ValueTask

Asynchronous task

Exceptions

OperationCanceledException

Operation has been cancelled

SocketException

Command could not be processed

See Also

ReceiveCode()

Wait for a code to be intercepted and read it

public Code ReceiveCode()

Returns

Code

Code being intercepted or null if the connection has been closed

Exceptions

SocketException

Command could not be processed

See Also

ReceiveCodeAsync(CancellationToken)

Wait for a code to be intercepted and read it asynchronously

public ValueTask<Code> ReceiveCodeAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Optional cancellation token

Returns

ValueTask<Code>

Code being intercepted or null if the connection has been closed

Exceptions

OperationCanceledException

Operation has been cancelled

SocketException

Command could not be processed

See Also

ResolveCode(Message)

Instruct the control server to resolve the last received code with the given message details (in intercepting mode)

public void ResolveCode(Message message)

Parameters

message Message

Message to resolve the code with

Exceptions

SocketException

Command could not be processed

See Also

ResolveCode(MessageType, string)

Instruct the control server to resolve the last received code with the given message details (in intercepting mode)

public void ResolveCode(MessageType type, string content)

Parameters

type MessageType

Type of the resolving message

content string

Content of the resolving message

Exceptions

SocketException

Command could not be processed

See Also

ResolveCodeAsync(Message, CancellationToken)

Instruct the control server to resolve the last received code with the given message details (in intercepting mode) asynchronously

public ValueTask ResolveCodeAsync(Message message, CancellationToken cancellationToken = default)

Parameters

message Message

Message to resolve the code with

cancellationToken CancellationToken

Optional cancellation token

Returns

ValueTask

Asynchronous task

Exceptions

OperationCanceledException

Operation has been cancelled

SocketException

Command could not be processed

See Also

ResolveCodeAsync(MessageType, string, CancellationToken)

Instruct the control server to resolve the last received code with the given message details (in intercepting mode) asynchronously

public ValueTask ResolveCodeAsync(MessageType type, string content, CancellationToken cancellationToken = default)

Parameters

type MessageType

Type of the resolving message

content string

Content of the resolving message

cancellationToken CancellationToken

Optional cancellation token

Returns

ValueTask

Asynchronous task

Exceptions

OperationCanceledException

Operation has been cancelled

SocketException

Command could not be processed

See Also

RewriteCode(Code)

Rewrite the code being intercepted. This effectively modifies the code before it is processed further

public void RewriteCode(Code code)

Parameters

code Code

Updated code

Exceptions

SocketException

Command could not be processed

See Also

RewriteCodeAsync(Code, CancellationToken)

Rewrite the code being intercepted asynchronously. This effectively modifies the code before it is processed further

public ValueTask RewriteCodeAsync(Code code, CancellationToken cancellationToken = default)

Parameters

code Code

Updated code

cancellationToken CancellationToken

Optional cancellation token

Returns

ValueTask

Asynchronous task

Exceptions

OperationCanceledException

Operation has been cancelled

SocketException

Command could not be processed

See Also

See Also