Class InterceptConnection
Connection class for intercepting G/M/T-codes from the control server
Implements
Inherited Members
Namespace: DuetAPIClient
Assembly: DuetAPIClient.dll
Syntax
public sealed class InterceptConnection : BaseCommandConnection, IDisposable
Constructors
InterceptConnection()
Creates a new connection in intercepting mode
Declaration
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.
Declaration
public bool AutoEvaluateExpressions { get; set; }
Property Value
Type | Description |
---|---|
bool |
AutoFlush
Automatically flush the code channel before notifying the client in case a code filter is specified
Declaration
public bool AutoFlush { get; set; }
Property Value
Type | Description |
---|---|
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!
Channels
List of input channels where codes may be intercepted. If the list is empty, all available channels are used
Declaration
public List<CodeChannel> Channels { get; set; }
Property Value
Type | Description |
---|---|
List<CodeChannel> |
Filters
List of G/M/T-codes to filter or Q0 for comments
Declaration
public List<string> Filters { get; set; }
Property Value
Type | Description |
---|---|
List<string> |
Remarks
This may only specify the code type and major/minor number (e.g. G1)
Mode
Mode of the interceptor
Declaration
public InterceptionMode Mode { get; }
Property Value
Type | Description |
---|---|
InterceptionMode |
PriortyCodes
Defines if priority codes may be intercepted (e.g. M122 or M999)
Declaration
public bool PriortyCodes { get; }
Property Value
Type | Description |
---|---|
bool |
See Also
Methods
CancelCode(CancellationToken)
Instruct the control server to cancel the last received code (in intercepting mode)
Declaration
public ValueTask CancelCode(CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | Optional cancellation token |
Returns
Type | Description |
---|---|
ValueTask | Asynchronous task |
Exceptions
Type | Condition |
---|---|
OperationCanceledException | Operation has been cancelled |
SocketException | Command could not be processed |
See Also
Connect(InterceptionMode, IEnumerable<CodeChannel>?, IEnumerable<string>?, bool, string, CancellationToken)
Establishes a connection to the given UNIX socket file
Declaration
public Task Connect(InterceptionMode mode, IEnumerable<CodeChannel>? channels = null, IEnumerable<string>? filters = null, bool priorityCodes = false, string socketPath = "/run/dsf/dcs.sock", CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
InterceptionMode | mode | Interception mode |
IEnumerable<CodeChannel> | channels | List of input channels where codes may be intercepted or null for all available channels |
IEnumerable<string> | filters | Optional list of codes that may be intercepted |
bool | priorityCodes | Define if priority codes may be intercepted |
string | socketPath | Path to the UNIX socket file |
CancellationToken | cancellationToken | Optional cancellation token |
Returns
Type | Description |
---|---|
Task | Asynchronous task |
Exceptions
Type | Condition |
---|---|
IncompatibleVersionException | API level is incompatible |
IOException | Connection mode is unavailable |
OperationCanceledException | Operation has been cancelled |
SocketException | Init message could not be processed |
Connect(InterceptionMode, string, CancellationToken)
Establishes a connection to the given UNIX socket file
Declaration
[Obsolete("Use the new overload to specify the code channels to intercept")]
public Task Connect(InterceptionMode mode, string socketPath, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
InterceptionMode | mode | Interception mode |
string | socketPath | Path to the UNIX socket file |
CancellationToken | cancellationToken | Optional cancellation token |
Returns
Type | Description |
---|---|
Task | Asynchronous task |
Exceptions
Type | Condition |
---|---|
IncompatibleVersionException | API level is incompatible |
IOException | Connection mode is unavailable |
OperationCanceledException | Operation has been cancelled |
SocketException | Init message could not be processed |
Flush(CancellationToken)
When intercepting a code wait for all previous codes of the given channel to finish
Declaration
public Task<bool> Flush(CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | Optional cancellation token |
Returns
Type | Description |
---|---|
Task<bool> | True if all pending codes could be flushed |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Requested code channel is disabled |
SocketException | Command could not be processed |
See Also
IgnoreCode(CancellationToken)
Instruct the control server to ignore the last received code (in intercepting mode)
Declaration
public ValueTask IgnoreCode(CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | Optional cancellation token |
Returns
Type | Description |
---|---|
ValueTask | Asynchronous task |
Exceptions
Type | Condition |
---|---|
OperationCanceledException | Operation has been cancelled |
SocketException | Command could not be processed |
See Also
ReceiveCode(CancellationToken)
Wait for a code to be intercepted and read it
Declaration
public ValueTask<Code> ReceiveCode(CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | Optional cancellation token |
Returns
Type | Description |
---|---|
ValueTask<Code> | Code being intercepted or null if the connection has been closed |
Exceptions
Type | Condition |
---|---|
OperationCanceledException | Operation has been cancelled |
SocketException | Command could not be processed |
See Also
ResolveCode(Message, CancellationToken)
Instruct the control server to resolve the last received code with the given message details (in intercepting mode)
Declaration
public ValueTask ResolveCode(Message message, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
Message | message | Message to resolve the code with |
CancellationToken | cancellationToken | Optional cancellation token |
Returns
Type | Description |
---|---|
ValueTask | Asynchronous task |
Exceptions
Type | Condition |
---|---|
OperationCanceledException | Operation has been cancelled |
SocketException | Command could not be processed |
See Also
ResolveCode(MessageType, string, CancellationToken)
Instruct the control server to resolve the last received code with the given message details (in intercepting mode)
Declaration
public ValueTask ResolveCode(MessageType type, string content, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
MessageType | type | Type of the resolving message |
string | content | Content of the resolving message |
CancellationToken | cancellationToken | Optional cancellation token |
Returns
Type | Description |
---|---|
ValueTask | Asynchronous task |
Exceptions
Type | Condition |
---|---|
OperationCanceledException | Operation has been cancelled |
SocketException | Command could not be processed |