Interface IProtocol
- Namespace
- MAS.Communication
- Assembly
- MAS.Communication.dll
所有通信协议的统一接口
public interface IProtocol : IDisposable
- Inherited Members
Properties
Configuration
获取通讯配置
ICommunicationConfig Configuration { get; }
Property Value
ProtocolType
获取协议类型
CommProtocol ProtocolType { get; }
Property Value
Methods
CheckConnection()
检查设备连接状态
bool CheckConnection()
Returns
- bool
连接活跃返回true,否则返回false
Remarks
部分协议中的实现只能作为快速判断
ConnectAsync(CancellationToken)
异步建立与设备的连接
Task ConnectAsync(CancellationToken cts = default)
Parameters
ctsCancellationToken取消令牌
Returns
- Task
表示一个异步操作任务
Exceptions
Disconnect()
关闭设备连接
void Disconnect()
ProbeConnectionAsync(CancellationToken)
异步测试设备连接,成功后自动关闭
Task<bool> ProbeConnectionAsync(CancellationToken cts = default)
Parameters
ctsCancellationToken取消令牌
Returns
Exceptions
TryReconnectAsync(int, int, CancellationToken)
异步尝试重新连接到设备
Task<bool> TryReconnectAsync(int maxAttempts, int retryDelay = 1000, CancellationToken cts = default)
Parameters
maxAttemptsint最多尝试次数
retryDelayint重试等待时间(毫秒)
ctsCancellationToken取消令牌
Returns
Remarks
在中途断线时调用此方法将尝试重新连接
Exceptions
Events
Disposed
当实例被释放后触发
event EventHandler? Disposed