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
AutoFlush
Automatically flush the code channel before notifying the client in case a code filter is specified
public bool AutoFlush { get; set; }
Property Value
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
Filters
List of G/M/T-codes to filter or Q0 for comments
public List<string> Filters { get; set; }
Property Value
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
PriortyCodes
Defines if priority codes may be intercepted (e.g. M122 or M999)
public bool PriortyCodes { get; }
Property Value
- 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
cancellationTokenCancellationTokenOptional 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
modeInterceptionModeInterception mode
channelsIEnumerable<CodeChannel>List of input channels where codes may be intercepted or null for all available channels
filtersIEnumerable<string>Optional list of codes that may be intercepted
priorityCodesboolDefine if priority codes may be intercepted
socketPathstringOptional 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
modeInterceptionModeInterception mode
channelsIEnumerable<CodeChannel>List of input channels where codes may be intercepted or null for all available channels
filtersIEnumerable<string>Optional list of codes that may be intercepted
priorityCodesboolDefine if priority codes may be intercepted
socketPathstringOptional path to the DCS UNIX socket file
cancellationTokenCancellationTokenOptional 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
cancellationTokenCancellationTokenOptional cancellation token
Returns
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
cancellationTokenCancellationTokenOptional 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
cancellationTokenCancellationTokenOptional cancellation token
Returns
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
messageMessageMessage 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
typeMessageTypeType of the resolving message
contentstringContent 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
messageMessageMessage to resolve the code with
cancellationTokenCancellationTokenOptional 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
typeMessageTypeType of the resolving message
contentstringContent of the resolving message
cancellationTokenCancellationTokenOptional 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
codeCodeUpdated 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
codeCodeUpdated code
cancellationTokenCancellationTokenOptional cancellation token
Returns
- ValueTask
Asynchronous task
Exceptions
- OperationCanceledException
Operation has been cancelled
- SocketException
Command could not be processed
- See Also