CarrierIdReader.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Aitex.Core.RT.Device;
  7. using Aitex.Core.RT.Event;
  8. using Aitex.Core.Util;
  9. using MECF.Framework.Common.Communications;
  10. using MECF.Framework.Common.Equipment;
  11. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.CarrierIdReaders
  12. {
  13. public class CarrierIdReader : BaseDevice, IDevice
  14. {
  15. public event Action<ModuleName, string, string> OnCarrierIdRead;
  16. public event Action<ModuleName, string> OnCarrierIdReadFailed;
  17. public event Action<ModuleName, string/*Name*/, string/*Code*/> OnCarrierIdWrite;
  18. public event Action<ModuleName, string/*Name*/> OnCarrierIdWriteFailed;
  19. private string _loadPort;
  20. public CarrierIdReader(string module, string name, string display="", string deviceId="", string address="", string page="", string loadport="") :base(module, name, name, name)
  21. {
  22. Module = module;
  23. Name = name;
  24. _loadPort = loadport;
  25. }
  26. public virtual bool Initialize()
  27. {
  28. DEVICE.Register(String.Format("{0}.{1}", Name, "ReadRFID"), (out string reason, int time, object[] param) =>
  29. {
  30. bool ret = Read(out reason);
  31. if (ret)
  32. {
  33. reason = string.Format("{0}{1}", Name, "Reading ID");
  34. return true;
  35. }
  36. return false;
  37. });
  38. DEVICE.Register(String.Format("{0}.{1}", Name, "WriteRFID"), (out string reason, int time, object[] param) =>
  39. {
  40. string id = (string)param[0];
  41. bool ret = Write(id, out reason);
  42. if (ret)
  43. {
  44. reason = string.Format("{0}{1}", Name, "Writing ID");
  45. return true;
  46. }
  47. return false;
  48. });
  49. return true;
  50. }
  51. public virtual bool Read(out string reason)
  52. {
  53. reason = string.Empty;
  54. return true;
  55. }
  56. public virtual bool Write(string id, out string reason)
  57. {
  58. reason = string.Empty;
  59. return true;
  60. }
  61. public virtual void Monitor()
  62. {
  63. }
  64. public virtual void Terminate()
  65. {
  66. }
  67. public virtual void Reset()
  68. {
  69. }
  70. public virtual bool Connect()
  71. {
  72. return true;
  73. }
  74. public bool SetManualScanCode(string code)
  75. {
  76. ReadOk(code);
  77. EV.PostInfoLog("System", "Manually scan code");
  78. return true;
  79. }
  80. public void ReadOk(string code)
  81. {
  82. if (OnCarrierIdRead != null)
  83. {
  84. OnCarrierIdRead((ModuleName)Enum.Parse(typeof(ModuleName), string.IsNullOrEmpty(Module) ? _loadPort : Module), Name, code);
  85. }
  86. }
  87. public void ReadFailed()
  88. {
  89. if (OnCarrierIdReadFailed != null)
  90. {
  91. OnCarrierIdReadFailed((ModuleName)Enum.Parse(typeof(ModuleName), string.IsNullOrEmpty(Module) ? _loadPort : Module), Name);
  92. }
  93. }
  94. public void WriteOk(string code)
  95. {
  96. if (OnCarrierIdWrite != null)
  97. {
  98. OnCarrierIdWrite((ModuleName)Enum.Parse(typeof(ModuleName), string.IsNullOrEmpty(Module) ? _loadPort : Module), Name, code);
  99. }
  100. }
  101. public void WriteFailed()
  102. {
  103. if (OnCarrierIdWriteFailed != null)
  104. {
  105. OnCarrierIdWriteFailed((ModuleName)Enum.Parse(typeof(ModuleName), string.IsNullOrEmpty(Module) ? _loadPort : Module), Name);
  106. }
  107. }
  108. }
  109. }