IConnector.cs 2.9 KB

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