Table of Contents

Interface IProtocol

Namespace
MAS.Communication
Assembly
MAS.Communication.dll

所有通信协议的统一接口

public interface IProtocol : IDisposable
Inherited Members

Properties

Configuration

获取通讯配置

ICommunicationConfig Configuration { get; }

Property Value

ICommunicationConfig

ProtocolType

获取协议类型

CommProtocol ProtocolType { get; }

Property Value

CommProtocol

Methods

CheckConnection()

检查设备连接状态

bool CheckConnection()

Returns

bool

连接活跃返回true,否则返回false

Remarks

部分协议中的实现只能作为快速判断

ConnectAsync(CancellationToken)

异步建立与设备的连接

Task ConnectAsync(CancellationToken cts = default)

Parameters

cts CancellationToken

取消令牌

Returns

Task

表示一个异步操作任务

Exceptions

OperationCanceledException
ConnectionException

Disconnect()

关闭设备连接

void Disconnect()

ProbeConnectionAsync(CancellationToken)

异步测试设备连接,成功后自动关闭

Task<bool> ProbeConnectionAsync(CancellationToken cts = default)

Parameters

cts CancellationToken

取消令牌

Returns

Task<bool>

一个异步操作任务,成功返回 true,否则返回 false

Exceptions

OperationCanceledException

TryReconnectAsync(int, int, CancellationToken)

异步尝试重新连接到设备

Task<bool> TryReconnectAsync(int maxAttempts, int retryDelay = 1000, CancellationToken cts = default)

Parameters

maxAttempts int

最多尝试次数

retryDelay int

重试等待时间(毫秒)

cts CancellationToken

取消令牌

Returns

Task<bool>

一个异步操作任务,成功连接则返回 true,否则返回 false

Remarks

在中途断线时调用此方法将尝试重新连接

Exceptions

OperationCanceledException

Events

Disposed

当实例被释放后触发

event EventHandler? Disposed

Event Type

EventHandler