HstHandler.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. using Aitex.Core.RT.Event;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.RT.SCCore;
  4. using Aitex.Sorter.Common;
  5. using MECF.Framework.Common.Communications;
  6. using MECF.Framework.Common.Equipment;
  7. using MECF.Framework.Common.SubstrateTrackings;
  8. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Text.RegularExpressions;
  14. using System.Threading;
  15. using System.Threading.Tasks;
  16. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.OcrReaders.HST
  17. {
  18. public abstract class HstHandler : HandlerBase
  19. {
  20. protected ModuleName _target;
  21. protected int _slot;
  22. public HstOcrReader OCRDevice { get; set; }
  23. public string Command;
  24. protected HstHandler(HstOcrReader device,string command,string para): base(BuildMessage(command,para))
  25. {
  26. OCRDevice = device;
  27. Command = command;
  28. //_isSimulator = SC.GetValue<bool>("System.IsSimulatorMode");
  29. }
  30. public static byte[] BuildMessage(string command, string para)
  31. {
  32. List<byte> ret = new List<byte>();
  33. foreach (char c in command)
  34. {
  35. ret.Add((byte)c);
  36. }
  37. //cmd.Add((byte)(':')); //3A
  38. if (!string.IsNullOrEmpty(para))
  39. foreach (char c in para)
  40. {
  41. ret.Add((byte)c);
  42. }
  43. return ret.ToArray();
  44. }
  45. public virtual void Update()
  46. {
  47. }
  48. }
  49. public class OnlineHandler: HstHandler
  50. {
  51. public OnlineHandler(HstOcrReader reader,bool online):base(reader,"SO",online?"1":"0")
  52. {
  53. OCRDevice = reader;
  54. Command = "SO";
  55. }
  56. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  57. {
  58. HstMessage response = msg as HstMessage;
  59. ResponseMessage = msg;
  60. if(response.IsAck) SetState(EnumHandlerState.Acked);
  61. if(response.IsNak) SetState(EnumHandlerState.Completed);
  62. transactionComplete = true;
  63. return true;
  64. }
  65. }
  66. public class LoadJobHandler : HstHandler
  67. {
  68. public LoadJobHandler(HstOcrReader reader, string jobfile) : base(reader, "LF", jobfile)
  69. {
  70. OCRDevice = reader;
  71. Command = string.Format("LF{0}.job", jobfile);
  72. }
  73. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  74. {
  75. HstMessage response = msg as HstMessage;
  76. ResponseMessage = msg;
  77. if (response.IsAck) SetState(EnumHandlerState.Acked);
  78. if (response.IsNak) SetState(EnumHandlerState.Completed);
  79. transactionComplete = true;
  80. return true;
  81. }
  82. }
  83. public class ReadLMHandler : HstHandler
  84. {
  85. public ReadLMHandler(HstOcrReader reader) : base(reader, "SM\"READ\"0 ", null)
  86. {
  87. OCRDevice = reader;
  88. Command = "SM\"READ\"0 ";
  89. }
  90. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  91. {
  92. HstMessage response = msg as HstMessage;
  93. ResponseMessage = msg;
  94. if (response.IsAck)
  95. {
  96. SetState(EnumHandlerState.Acked);
  97. transactionComplete = false;
  98. return true;
  99. }
  100. if (response.IsNak) SetState(EnumHandlerState.Completed);
  101. if (response.IsResponse)
  102. {
  103. SetState(EnumHandlerState.Completed);
  104. string[] items = response.Data.TrimStart('[').TrimEnd(']').Split(',');
  105. if (OCRDevice.ReadLaserMaker)
  106. {
  107. OCRDevice.LaserMaker = items[0];
  108. OCRDevice.LaserMark1 = items[0];
  109. if (items.Length > 1) OCRDevice.LaserMark1Score = items[1];
  110. if (items.Length > 2) OCRDevice.LaserMark1ReadTime = items[2];
  111. LOG.Write($"{OCRDevice.Name} laser mark1 updated to {OCRDevice.LaserMaker}");
  112. }
  113. else
  114. {
  115. OCRDevice.T7Code = items[0];
  116. OCRDevice.LaserMark2 = items[0];
  117. if (items.Length > 1) OCRDevice.LaserMark2Score = items[1];
  118. if (items.Length > 2) OCRDevice.LaserMark2ReadTime = items[2];
  119. LOG.Write($"{OCRDevice.Name} laser mark2 updated to {OCRDevice.T7Code}");
  120. }
  121. OCRDevice.ReadOK = double.Parse(items[1]) >= 0;
  122. }
  123. transactionComplete = true;
  124. return true;
  125. }
  126. }
  127. }