CytAsciiDefine.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.InteropServices;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows.Documents;
  8. namespace EPD.Data
  9. {
  10. public class CytAsciiDefine
  11. {
  12. public static Dictionary<int, string> ErrorMap = new Dictionary<int, string>()
  13. {
  14. {0x0000, "OK"},
  15. {0x1000, "Format error"},
  16. {0x1001, "Parameter invalid"},
  17. {0x1002, "EPD not online"},
  18. {0x1003, "EPD is initializing"},
  19. {0x1004, "EPD config file has invalid setting"},
  20. {0x1005, "EPD calculation failed"},
  21. {0x1006, "EPD not remote"},
  22. { 0x1100, "Device has other error" },
  23. { 0x1101, "Device nvalid" },
  24. { 0x1102, "No Device" },
  25. { 0x1103, "Device close failed" },
  26. { 0x1104, "Device: order not implemented" },
  27. { 0x1105, "Device: a features not found" },
  28. { 0x1106, "Device: transfer Error" },
  29. { 0x1107, "Device: bad user buffer" },
  30. { 0x1108, "Device: out of bounds" },
  31. { 0x1109, "Device Saturated" },
  32. {0x2000, "EPD device error"},
  33. };
  34. public static Dictionary<int, string> StateMap = new Dictionary<int, string>()
  35. {
  36. {0, "OK"},
  37. {1, "SYNTAX ERROR: The number of zero limiters in the header is not correct."},
  38. {2, "SYNTAX ERROR: The number of zero limiters in the body is not correct."},
  39. {3, "SYNTAX ERROR: The numbers of items in the body do not match the header."},
  40. {4, "SYNTAX ERROR: Correct value is required."},
  41. {5, "SYNTAX ERROR: Recognizable text character is required"},
  42. {6, "MESSAGE ERROR: The numbers of items in the body do not conform to specifications."},
  43. {7, "HEADER ERROR: Numerical value is beyond the defined range."},
  44. {8, "HEADER ERROR: The text is not of defined size."},
  45. {9, "BODY ERROR: Numerical value is beyond the deined range."},
  46. {10, "BODY ERROR: The tetx is not of defined size."},
  47. {11, "Sensor ID does not match the current sensor setting."},
  48. {12, "WatchDog Code: The remote control system is not ready."},
  49. {13, "WatchDog Code: The sensor subsystem is not ready"},
  50. {14, "WatchDog Code: The cluster control subsystem is not ready."},
  51. {15, "WatchDog Code: The available hard disk capacity has reached its upper limit."},
  52. {16, "WatchDog Code: Mismatch between step names occurred."},
  53. {17, "Step name is missing."},
  54. {18, "Required action is beyond the defined range."},
  55. {19, "Warning is raised in the sensor subsystem."},
  56. };
  57. }
  58. public enum CytAsciiEvent
  59. {
  60. Event_Message = 0x01,
  61. Event_SystemError = 0x02,
  62. Event_StepStart = 0x03,
  63. Event_StepDelay = 0x04,
  64. Event_StepNormalize = 0x05,
  65. Event_StepSatisfied = 0x06,
  66. Event_StepTrigger = 0x07,
  67. Event_StepStop = 0x08,
  68. Event_TrendData = 0x10,
  69. }
  70. public enum CytAsciiCommand
  71. {
  72. Reset = 0x00,
  73. RecipeStart = 0x01,
  74. RecipeStop = 0x02,
  75. Complete = 0x03,
  76. Start = 0x04,
  77. Stop = 0x05,
  78. SetWaferInfo = 0x06,
  79. QueryCfgList = 0x07,
  80. QueryState = 0x08,
  81. QueryVer = 0x09,
  82. Event = 0x0A,
  83. Connect = 0x10,
  84. Disconnect = 0x11,
  85. HeartBeat = 0x20,
  86. QueryData = 0x30,
  87. QueryRunStatus = 0x31,
  88. SetRunStatus = 0x32,
  89. QueryOperateMode = 0x33,
  90. SetOperateMode = 0x34,
  91. }
  92. public class CytAsciiData
  93. {
  94. public int MessageID { get; set; }
  95. public int CommandID { get; set; }
  96. public string SenderID { get; set; }
  97. public string ReceiveID { get; set; }
  98. public List<string> Params { get; set; }
  99. public CytAsciiData(int messageID, int commandID, string senderID, string receiveID)
  100. {
  101. MessageID = messageID;
  102. CommandID = commandID;
  103. SenderID = senderID;
  104. ReceiveID = receiveID;
  105. Params = new List<string>();
  106. }
  107. private List<string> ToList()
  108. {
  109. var lst = new List<string> {MessageID.ToString(), CommandID.ToString(), SenderID, ReceiveID, Params.Count.ToString() };
  110. lst.AddRange(Params);
  111. return lst;
  112. }
  113. public byte[] ToBytes()
  114. {
  115. var lst = ToList();
  116. var length = 2;
  117. foreach (var item in lst)
  118. length += item.Length + 1;
  119. var pos = 0;
  120. var bytes = new byte[length];
  121. foreach (var item in lst)
  122. {
  123. Buffer.BlockCopy(Encoding.UTF8.GetBytes(item), 0, bytes, pos, item.Length);
  124. pos += item.Length + 1;
  125. }
  126. bytes[pos] = 0x0D;
  127. bytes[pos + 1] = 0x0A;
  128. return bytes;
  129. }
  130. public static List<string> ToList(byte[] bytes, int index, ref int len)
  131. {
  132. var lst = new List<string>();
  133. var startIndex = index;
  134. for (int i = index; i < index + len - 1; i++)
  135. {
  136. if (bytes[i] == 0)
  137. {
  138. lst.Add(Encoding.UTF8.GetString(bytes, startIndex, i - startIndex));
  139. startIndex = i + 1;
  140. }
  141. else if (bytes[i] == 0x0D && bytes[i + 1] == 0x0A)
  142. {
  143. len = i - index + 2;
  144. return lst;
  145. }
  146. }
  147. len = -1;
  148. return lst;
  149. }
  150. }
  151. public struct CytAsciiResponseHeader
  152. {
  153. public static readonly int Size = Marshal.SizeOf(typeof(ResponseHeader));
  154. [MarshalAs(UnmanagedType.U4, SizeConst = 4)]
  155. public int token;
  156. [MarshalAs(UnmanagedType.U1, SizeConst = 1)]
  157. public byte channel;
  158. [MarshalAs(UnmanagedType.U1, SizeConst = 1)]
  159. public byte command;
  160. [MarshalAs(UnmanagedType.U4, SizeConst = 4)]
  161. public int errorcode;
  162. [MarshalAs(UnmanagedType.U4, SizeConst = 4)]
  163. public int length;
  164. }
  165. }