BaseConnector.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System;
  2. using System.Threading.Tasks;
  3. using Team.Communicate.EventArg;
  4. using Team.Communicate.Interfaces;
  5. namespace Team.Communicate.Client
  6. {
  7. /// <summary>
  8. /// 基础的协议连接类
  9. /// </summary>
  10. public abstract class BaseConnector : BaseConnector<byte[], byte[]>
  11. {
  12. }
  13. /// <summary>
  14. /// 基础的协议连接类
  15. /// </summary>
  16. public abstract class BaseConnector<TParamIn, TParamOut> : IConnector<TParamIn, TParamOut>
  17. {
  18. /// <summary>
  19. /// 标识Connector的连接关键字
  20. /// </summary>
  21. public abstract string ConnectionToken { get; }
  22. /// <summary>
  23. /// 是否处于连接状态
  24. /// </summary>
  25. public abstract bool IsConnected { get; }
  26. /// <summary>
  27. /// 连接PLC
  28. /// </summary>
  29. /// <returns>是否连接成功</returns>
  30. public abstract bool Connect();
  31. /// <summary>
  32. /// 连接PLC,异步
  33. /// </summary>
  34. /// <returns>是否连接成功</returns>
  35. public abstract Task<bool> ConnectAsync();
  36. /// <summary>
  37. /// 断开PLC
  38. /// </summary>
  39. /// <returns>是否断开成功</returns>
  40. public abstract bool Disconnect();
  41. /// <summary>
  42. /// 无返回发送数据
  43. /// </summary>
  44. /// <param name="message">需要发送的数据</param>
  45. /// <returns>是否发送成功</returns>
  46. public abstract bool SendMsgWithoutReturn(TParamIn message);
  47. /// <summary>
  48. /// 无返回发送数据
  49. /// </summary>
  50. /// <param name="message">需要发送的数据</param>
  51. /// <returns>是否发送成功</returns>
  52. public abstract Task<bool> SendMsgWithoutReturnAsync(TParamIn message);
  53. /// <summary>
  54. /// 带返回发送数据
  55. /// </summary>
  56. /// <param name="message">需要发送的数据</param>
  57. /// <returns>是否发送成功</returns>
  58. public abstract TParamOut SendMsg(TParamIn message);
  59. /// <summary>
  60. /// 带返回发送数据
  61. /// </summary>
  62. /// <param name="message">需要发送的数据</param>
  63. /// <returns>是否发送成功</returns>
  64. public abstract Task<TParamOut> SendMsgAsync(TParamIn message);
  65. public abstract event EventHandler<string> SendEventHandler;
  66. public abstract event EventHandler<ExceptionEventArgs<Exception>> SendExceptionEventHandler;
  67. public abstract event EventHandler<string> ConnectedEventHandler;
  68. public abstract event EventHandler<ExceptionEventArgs<Exception>> ConnectExceptionEventHandler;
  69. public abstract event EventHandler<string> ReceiveEventHandler;
  70. public abstract event EventHandler<ExceptionEventArgs<Exception>> ReceiveExceptionEventHandler;
  71. public abstract event EventHandler<string> DisConnectEvent;
  72. public abstract event EventHandler<ExceptionEventArgs<Exception>> DisConnectFailEvent;
  73. }
  74. }