ICommunication.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace Aitex.Sorter.RT.Device
  6. {
  7. public class ErrorEventArgs : EventArgs
  8. {
  9. public readonly string Reason;
  10. public readonly string Code;
  11. public ErrorEventArgs(string reason, string code = "")
  12. {
  13. Reason = reason;
  14. Code = code;
  15. }
  16. }
  17. public class DataEventArgs : EventArgs
  18. {
  19. public readonly string Data;
  20. public DataEventArgs(string data)
  21. {
  22. Data = data;
  23. }
  24. }
  25. public interface ICommunication
  26. {
  27. bool Write(string msg);
  28. }
  29. public interface IHandler
  30. {
  31. int ID { get; set; }
  32. int Unit { get; set; }
  33. bool IsBackground { get; }
  34. bool Execute<T>(ref T port) where T : ICommunication;
  35. /// <summary>
  36. /// return value : handle
  37. /// </summary>
  38. /// <typeparam name="T"></typeparam>
  39. /// <param name="port"></param>
  40. /// <param name="msg"></param>
  41. /// <param name="completed"></param>
  42. /// <returns></returns>
  43. bool OnMessage<T>(ref T port, string msg, out bool completed) where T : ICommunication;
  44. }
  45. public class InvalidPackageException : ApplicationException
  46. {
  47. public InvalidPackageException(string msg) : base(msg)
  48. {
  49. }
  50. public override string Message
  51. {
  52. get
  53. {
  54. return base.Message;
  55. }
  56. }
  57. }
  58. public class ExcuteFailedException : ApplicationException
  59. {
  60. public ExcuteFailedException(string msg)
  61. : base(msg)
  62. {
  63. }
  64. public override string Message
  65. {
  66. get
  67. {
  68. return base.Message;
  69. }
  70. }
  71. }
  72. }