RorzePreAligner.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. using Aitex.Core.RT.SCCore;
  2. using Aitex.Core.Util;
  3. using Aitex.Sorter.Common;
  4. using athosRT.tool;
  5. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Text.RegularExpressions;
  11. using System.Threading.Tasks;
  12. namespace athosRT.Devices.PA
  13. {
  14. public class RorzePreAligner : PreAligner
  15. {
  16. #region 私有变量
  17. private string _address;//地址
  18. private string _port;//端口
  19. private readonly AsyncSocket _socket;//通讯socket
  20. private string _newLine = "\r";
  21. private object _locker = new object();
  22. private bool _isAsciiMode;
  23. private LinkedList<string> _lstAsciiMsgs = new LinkedList<string>();
  24. private Regex catch_parameter = new Regex(@"(?<=\:)(.*)");//获取:后续参数
  25. private bool _errorflag;
  26. private PeriodicJob _thread;
  27. private Dictionary<string, string> cancelcode2msg = new Dictionary<string, string>()
  28. {
  29. {"0001","Command not designated" },
  30. {"0002","The designated target motion not equipped" },
  31. {"0003","Too many/too few parameters (number of elements)" },
  32. {"0004","Command not equipped" },
  33. {"0005","Too many/too few parameters" },
  34. {"0006","Abnormal range of the parameter" },
  35. {"0007","Abnormal mode" },
  36. {"0008","Abnormal data" },
  37. {"0009","System in preparation" },
  38. {"000A","Origin search not completed" },
  39. {"000B","Moving/Processing" },
  40. {"000C","No motion" },
  41. {"000D","Abnormal flash memory" },
  42. {"000E","Insufficient memory" },
  43. {"000F","Error-occurred state" },
  44. {"0010","Origin search is completed but the motion cannot be started due to interlock." },
  45. {"0011","The emergency stop signal is turned on." },
  46. {"0012","The temporarily stop signal is turned on." },
  47. {"0013","Abnormal interlock signal" },
  48. {"0014","Drive power is turned off." },
  49. {"0015","Not excited" },
  50. {"0016","Abnormal current position" },
  51. {"0017","Abnormal target position" },
  52. {"0018","Command processing" },
  53. {"0019","Invalid substrate state" },
  54. {"0020","Substrate yet to be aligned" },
  55. {"FFFF","Fatal error is occurring.need to cycle the power." },
  56. };
  57. private Dictionary<string, string> errorcode2msg = new Dictionary<string, string>()
  58. {
  59. {"01","Motor stall" },
  60. {"02","Limit" },
  61. {"03","Limit" },
  62. {"04","Command error" },
  63. {"05","Communication error" },
  64. {"06","Abnormal sensor" },
  65. {"07","Driver EMS error" },
  66. {"08","Substrate dropped error" },
  67. {"0E","Abnormal driver" },
  68. {"0F","Abnormal drive power" },
  69. {"10","Abnormal control power" },
  70. {"13","Abnormal temperature of driver" },
  71. {"14","Driver FPGA error" },
  72. {"15","Motor wire broken" },
  73. {"16","Motor over load" },
  74. {"17","Motor motion start error" },
  75. {"18","Abnormal alignment sensor" },
  76. {"19","Abnormal exhaust FAN state" },
  77. {"1A","Alignment sensor detects obstacle" },
  78. {"40","Internal error (abnormal device driver)" },
  79. {"41","Internal error (abnormal driver control)" },
  80. {"42","Internal error (task start failed)" },
  81. {"45","Reading setting data failed" },
  82. {"7E","CPU reset error" },
  83. {"7F","Controller internal memory error" },
  84. {"80","Intelock signal is abnormal" },
  85. {"83","Origin search failed" },
  86. {"84","Chucking error" },
  87. {"90","Notch detection error" },
  88. {"91","Alignment sensor detects obstacle" },
  89. {"92","Retry over (alignment failed)" },
  90. {"93","Shifting motion retry over" },
  91. {"96","Sub o-flat location error" },
  92. {"97","Substrate center deviation error" },
  93. };
  94. private PAStatus _status;
  95. #endregion
  96. #region 暴露变量
  97. public override PAStatus Status => _status;
  98. public override bool IsConnected => _socket.IsConnected;
  99. public override bool Busy => _status != PAStatus.Idle && _status != PAStatus.Init ;
  100. public override bool Moving => base.Moving;
  101. public override bool Error => _errorflag;
  102. //public override bool WaferOnAligner => base.WaferOnAligner;
  103. public PAStatus AlignStatus => _status;
  104. #endregion
  105. /// <summary>
  106. /// PA的关键点
  107. /// 通信方式:网口
  108. /// 主要功能:1、旋转对齐 2、初始化位置HOME 3、除错 4、重置 5、中断
  109. /// </summary>
  110. /// <param name="module"></param>
  111. /// <param name="name"></param>
  112. /// <param name="display"></param>
  113. /// <param name="deviceId"></param>
  114. /// <param name="address"></param>
  115. public RorzePreAligner(string module, string name, string display, string deviceId, string address) : base(module, name, display, deviceId, address)
  116. {
  117. base.Module = module;
  118. base.Name = name;
  119. _address = SC.GetStringValue($"{name}.Address");//从SC获取address
  120. _isAsciiMode = true;
  121. _socket = new AsyncSocket(_address, _newLine);
  122. _socket.OnDataChanged += OnReceiveMessage;
  123. _errorflag = false;
  124. _status = PAStatus.Init;
  125. Connect();
  126. _thread = new PeriodicJob(50, OnTimer, $"{name}->RT", true);
  127. }
  128. /// <summary>
  129. /// 定时函数 用来监听最新收到的消息 并交给函数处理
  130. /// </summary>
  131. /// <returns></returns>
  132. private bool OnTimer()
  133. {
  134. //处理消息
  135. lock (_locker)
  136. {
  137. if (_isAsciiMode)//按照ascii码处理
  138. {
  139. while (_lstAsciiMsgs.Count > 0)
  140. {
  141. string value = _lstAsciiMsgs.First.Value;
  142. HandleAsciiData(value);
  143. _lstAsciiMsgs.RemoveFirst();
  144. }
  145. }
  146. }
  147. return true;
  148. }
  149. //当收到新数据时
  150. private void OnReceiveMessage(string RevMsg)
  151. {
  152. //处理粘包 按照newline拆开
  153. lock (_locker)
  154. {
  155. if (string.IsNullOrEmpty(_newLine))//没有CR
  156. {
  157. _lstAsciiMsgs.AddLast(RevMsg);//将消息添加到最后
  158. return;
  159. }
  160. string[] array = RevMsg.Split(_newLine.ToCharArray());//按照cr分开通讯数据
  161. foreach (string text in array)
  162. {
  163. if (!string.IsNullOrEmpty(text))
  164. {
  165. _lstAsciiMsgs.AddLast(text + _newLine);//存进list中等待处理
  166. }
  167. }
  168. }
  169. }
  170. //利用定时器 对处理好的数据进行处理
  171. private void HandleAsciiData(string msg)
  172. {
  173. try
  174. {
  175. //不是空的情况下
  176. if (!string.IsNullOrEmpty(msg))
  177. {
  178. //首先处理头
  179. switch (msg[0])
  180. {
  181. case 'n':
  182. //错误处理代码
  183. LogObject.Error(Name, "传参不符合格式");
  184. break;
  185. case 'c':
  186. //取消处理代码
  187. string param_code = catch_parameter.Match(msg).Value;
  188. if (cancelcode2msg.ContainsKey(param_code))
  189. {
  190. string cancel_reason = cancelcode2msg[param_code];
  191. LogObject.Error(Name, cancel_reason);
  192. }
  193. else
  194. LogObject.Error(Name, "未定义相关cancel code");
  195. break;
  196. case 'e':
  197. //大于7说明错误代码是存在的
  198. if (msg.Length > 7)
  199. {
  200. //提取最后两位错误 作为索引
  201. string errorcode = msg.Substring(msg.Length-2,2);
  202. if (errorcode2msg.ContainsKey(errorcode))
  203. {
  204. string error_reason = errorcode2msg[errorcode];
  205. LogObject.Error(Name, error_reason);
  206. }
  207. _errorflag = true;
  208. }
  209. break;
  210. case 'a':
  211. //正常结束
  212. _status = PAStatus.Idle;
  213. break;
  214. default:
  215. break;
  216. }
  217. }
  218. }
  219. catch (Exception ex)
  220. {
  221. LogObject.Error(Name, ex);
  222. }
  223. }
  224. public override bool Connect()
  225. {
  226. _socket.Connect(_address);
  227. return _socket.IsConnected;
  228. }
  229. public override bool Disconnect()
  230. {
  231. _socket.Dispose();
  232. return _socket.IsConnected;
  233. }
  234. public override bool Home(out string reason)
  235. {
  236. reason = "";
  237. if (_socket.Write("oALN1.HOME"+_newLine) && _status != PAStatus.Home)
  238. _status = PAStatus.Home;
  239. return _status == PAStatus.Home;
  240. }
  241. public override bool Align(double angle, out string reason)
  242. {
  243. reason = "";
  244. //1基板对齐
  245. //7不吸附的对齐
  246. //10双O基板对齐
  247. //11双O基板亚O面对齐
  248. if(_socket.Write($"oALN1.ALGN(1,{angle})"+_newLine))
  249. _status = PAStatus.Align;
  250. return _status == PAStatus.Align;
  251. }
  252. public override bool Clear(out string reason)
  253. {
  254. //利用RSTA清错误
  255. reason = "";
  256. if(_socket.Write("oALN1.RSTA(1)"+_newLine))
  257. _status = PAStatus.Reset;
  258. return _status == PAStatus.Reset;
  259. }
  260. public override bool Init(out string reason)
  261. {
  262. //初始化
  263. reason = "";
  264. return _socket.Write("oALN1.INIT" + _newLine);
  265. }
  266. public override void Reset()
  267. {
  268. //重置
  269. _status = PAStatus.Reset;
  270. if (_socket.Write("oALN1.RSTA(1)" + _newLine))
  271. _status = PAStatus.Reset;
  272. }
  273. public override bool Stop(out string reason)
  274. {
  275. //停止
  276. reason = "";
  277. return _socket.Write("oALN1.STOP" + _newLine);
  278. }
  279. public override void Terminate()
  280. {
  281. //暂停
  282. _socket.Write("oALN1.PAUS" + _newLine);
  283. }
  284. public override bool QueryState(out string reason)
  285. {
  286. //查询设备状态
  287. reason = "";
  288. return _socket.Write("oALN1.STAT" + _newLine);
  289. }
  290. public override bool Initialize()
  291. {
  292. return true;
  293. }
  294. public override bool Grip(Hand hand, out string reason)
  295. {
  296. return base.Grip(hand, out reason);
  297. }
  298. public override bool Release(Hand hand, out string reason)
  299. {
  300. return base.Release(hand, out reason);
  301. }
  302. public override bool LiftDown(out string reason)
  303. {
  304. return base.LiftDown(out reason);
  305. }
  306. public override bool LiftUp(out string reason)
  307. {
  308. return base.LiftUp(out reason);
  309. }
  310. public override void Monitor()
  311. {
  312. base.Monitor();
  313. }
  314. public override bool MoveToReady(out string reason)
  315. {
  316. return base.MoveToReady(out reason);
  317. }
  318. public override string ToString()
  319. {
  320. return base.ToString();
  321. }
  322. public override bool Equals(object obj)
  323. {
  324. return base.Equals(obj);
  325. }
  326. public override int GetHashCode()
  327. {
  328. return base.GetHashCode();
  329. }
  330. }
  331. }