EdwardsPumpHandler.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. using Aitex.Core.RT.Device;
  2. using MECF.Framework.Common.Communications;
  3. using Newtonsoft.Json.Linq;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Runtime.InteropServices;
  7. using System.Text;
  8. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Pumps.EdwardsPump
  9. {
  10. public abstract class EdwardsPumpHandler : HandlerBase
  11. {
  12. public EdwardsPump Device { get; }
  13. public string _command;
  14. protected string _parameter;
  15. protected EdwardsPumpHandler(EdwardsPump device, string command,string parameter)
  16. : base(BuildMessage(command, parameter))
  17. {
  18. Device = device;
  19. _command = command;
  20. _parameter = parameter;
  21. Name = command;
  22. }
  23. private static string _endLine = "\r";
  24. private static string BuildMessage(string command, string parameter)
  25. {
  26. if(string.IsNullOrEmpty(parameter))
  27. return command + _endLine;
  28. else
  29. return command + parameter + _endLine;
  30. }
  31. public override bool HandleMessage(MessageBase msg, out bool handled)
  32. {
  33. EdwardsPumpMessage response = msg as EdwardsPumpMessage;
  34. ResponseMessage = msg;
  35. if (response.IsAck)
  36. {
  37. SetState(EnumHandlerState.Acked);
  38. if (msg.IsError)
  39. {
  40. Device.NoteError($"Command '{_command}' Error: {response.Data}:{ErrorString(response.ErrorText)}");
  41. }
  42. else
  43. {
  44. SetState(EnumHandlerState.Completed);
  45. handled = true;
  46. Device.NoteError(null);
  47. return true;
  48. }
  49. }
  50. handled = false;
  51. return false;
  52. }
  53. private static Dictionary<string, string> ErrorDict = new Dictionary<string, string>()
  54. {
  55. {"1","Invalid message" },
  56. {"2","Number not found" },
  57. {"3","Number Invalid" },
  58. {"4","Parameter’s value not received" },
  59. {"5","Command not possible" }
  60. };
  61. private static string ErrorString(string errorCode)
  62. {
  63. if (ErrorDict.ContainsKey(errorCode))
  64. return ErrorDict[errorCode];
  65. else
  66. return "NotDefined error";
  67. }
  68. }
  69. public class EdwardsPumpRawCommandHandler : EdwardsPumpHandler
  70. {
  71. public EdwardsPumpRawCommandHandler(EdwardsPump device, string command, string parameter)
  72. : base(device, command, parameter)
  73. {
  74. }
  75. public override bool HandleMessage(MessageBase msg, out bool handled)
  76. {
  77. if(base.HandleMessage(msg, out handled))
  78. {
  79. var result = msg as EdwardsPumpMessage;
  80. Device.NoteRawCommandInfo(_command, result.RawMessage);
  81. }
  82. return true;
  83. }
  84. }
  85. public class EdwardsPumpSimpleSwitchHandler : EdwardsPumpHandler
  86. {
  87. public EdwardsPumpSimpleSwitchHandler(EdwardsPump device, string command, string parameter)
  88. : base(device, command, parameter)
  89. {
  90. }
  91. public override bool HandleMessage(MessageBase msg, out bool handled)
  92. {
  93. if(base.HandleMessage(msg, out handled))
  94. {
  95. Device.NoteSwitchCompleted();
  96. }
  97. return true;
  98. }
  99. }
  100. public class PfeifferPumpSetPumpParameterHandler : EdwardsPumpHandler
  101. {
  102. public PfeifferPumpSetPumpParameterHandler(EdwardsPump device, string parameter)
  103. : base(device, "SET", parameter)
  104. {
  105. }
  106. public override bool HandleMessage(MessageBase msg, out bool handled)
  107. {
  108. if (base.HandleMessage(msg, out handled))
  109. {
  110. Device.NoteSetParaCompleted();
  111. }
  112. return true;
  113. }
  114. }
  115. public class EdwardsPumpReadAlarmStatusHandler : EdwardsPumpHandler
  116. {
  117. public EdwardsPumpReadAlarmStatusHandler(EdwardsPump device, string parameter)
  118. : base(device, "?A", parameter)
  119. {
  120. }
  121. public override bool HandleMessage(MessageBase msg, out bool handled)
  122. {
  123. if (base.HandleMessage(msg, out handled))
  124. {
  125. var result = msg as EdwardsPumpMessage;
  126. Device.NoteAlarmStatus(_parameter, result.Data);
  127. }
  128. return true;
  129. }
  130. }
  131. public class EdwardsQueryPumpStatusHandler : EdwardsPumpHandler
  132. {
  133. public EdwardsQueryPumpStatusHandler(EdwardsPump pump)
  134. : base(pump, "?P","")
  135. {
  136. Name = "Query Pump Status";
  137. }
  138. public override bool HandleMessage(MessageBase msg, out bool handled)
  139. {
  140. if (base.HandleMessage(msg, out handled))
  141. {
  142. EdwardsPumpMessage response = msg as EdwardsPumpMessage;
  143. var msgArry = response.Data.Split(',');
  144. if(msgArry.Length == 7)
  145. {
  146. //0=Switched off
  147. //1=Off, switching on
  148. //2=On, switching off (shut down after fault)
  149. //3=On, switching off (normal shut down)
  150. //4=on
  151. var statusLevel = msgArry[0];
  152. if (statusLevel == "4")
  153. Device.IsOn = true;
  154. else
  155. Device.IsOn = false;
  156. //0=Indication only; no warning or alarm.
  157. //1=Warning condition exists
  158. //2=Alarm condition exists: shut down the pump unless run til crash is set.
  159. //3=Alarm condition exists: shut down the pump.
  160. var priorityLevel = msgArry[1];
  161. //if (priorityLevel == "0")
  162. // Device.IsError = false;
  163. //else
  164. // Device.IsError = true;
  165. //0=No alarm
  166. //1= Digital alarm
  167. //9= Low warning
  168. //10=Low alarm
  169. //11=High warning
  170. //12=High alarm
  171. //13=Device error
  172. //14=Device not present
  173. var alarmType = msgArry[2];
  174. if (alarmType == "0" && priorityLevel == "0")
  175. Device.IsError = false;
  176. else
  177. Device.IsError = true;
  178. //0=Module missing
  179. //1=Sensor present at switch-on, but now disconnected
  180. //2=Wrong gas module fitted
  181. //3=Voltage above valid maximum voltage
  182. //4=Voltage below valid minimum voltage
  183. //5=ADC (analogue to digital convertor) not operating
  184. //6=Electrical supply has been interrupted
  185. //7=Watchdog reset has occurred
  186. //8=Sensor missing at switch on
  187. //9=Module switching on
  188. //10=No current consumption at pump switch-on
  189. //11=Wrong phase input to pump
  190. //12=EMS (emergency stop) has been activated
  191. //13=Flow sensor zero out of range
  192. //14=Cannot zero sensors
  193. //15=Configuration set read error
  194. var bitfieldStatus = msgArry[3];
  195. //1=run til crash is selected
  196. //0=run til crash is not selected
  197. var runTilCrashStatus = msgArry[4];
  198. //1=On process flag is set
  199. //0=On process flag is not set
  200. var onProcessStatus = msgArry[5];
  201. //0=No module has control
  202. //91=Single Pumpset Monitor has control
  203. //101=Pump Display Module has control
  204. //102=Remote Display has control
  205. //121=Parallel (tool) interface has control
  206. //181=Serial interface has control
  207. var controlObject = msgArry[6];
  208. }
  209. if(msgArry.Length == 1)
  210. {
  211. var statusLevel = msgArry[0];
  212. }
  213. Device.NoteSetParaCompleted();
  214. }
  215. return true;
  216. }
  217. }
  218. public class EdwardsExitSimulationModeHandler : EdwardsPumpHandler
  219. {
  220. public EdwardsExitSimulationModeHandler(EdwardsPump pump)
  221. : base(pump, "!M0", "")
  222. {
  223. Name = "Command Simulation Mode";
  224. }
  225. public override bool HandleMessage(MessageBase msg, out bool handled)
  226. {
  227. if (base.HandleMessage(msg, out handled))
  228. {
  229. Device.NoteSetParaCompleted();
  230. }
  231. return true;
  232. }
  233. }
  234. public class EdwardsEnterSimulationModeHandler : EdwardsPumpHandler
  235. {
  236. public EdwardsEnterSimulationModeHandler(EdwardsPump pump)
  237. : base(pump, "!M1", "")
  238. {
  239. Name = "Command Simulation Mode";
  240. }
  241. public override bool HandleMessage(MessageBase msg, out bool handled)
  242. {
  243. if (base.HandleMessage(msg, out handled))
  244. {
  245. Device.NoteSetParaCompleted();
  246. }
  247. return true;
  248. }
  249. }
  250. public class EdwardsFormatModeHandler : EdwardsPumpHandler
  251. {
  252. public EdwardsFormatModeHandler(EdwardsPump pump, bool isLongReplay)
  253. : base(pump, $"!F{(isLongReplay ? "1" : "0")}", "")
  254. {
  255. Name = "Format mode";
  256. }
  257. public override bool HandleMessage(MessageBase msg, out bool handled)
  258. {
  259. if (base.HandleMessage(msg, out handled))
  260. {
  261. Device.NoteSetParaCompleted();
  262. }
  263. return true;
  264. }
  265. }
  266. public class EdwardsGetControlHandler : EdwardsPumpHandler
  267. {
  268. public EdwardsGetControlHandler(EdwardsPump pump)
  269. : base(pump, "!C1", "")
  270. {
  271. Name = "Get control";
  272. }
  273. public override bool HandleMessage(MessageBase msg, out bool handled)
  274. {
  275. if (base.HandleMessage(msg, out handled))
  276. {
  277. Device.NoteSetParaCompleted();
  278. }
  279. return true;
  280. }
  281. }
  282. public class EdwardsSwitchOnPumpHandler : EdwardsPumpHandler
  283. {
  284. public EdwardsSwitchOnPumpHandler(EdwardsPump pump)
  285. : base(pump, "!P1", "")
  286. {
  287. Name = "Switch On Pump";
  288. }
  289. public override bool HandleMessage(MessageBase msg, out bool handled)
  290. {
  291. if (base.HandleMessage(msg, out handled))
  292. {
  293. Device.NoteSetParaCompleted();
  294. }
  295. return true;
  296. }
  297. }
  298. public class EdwardsSwitchOffPumpHandler : EdwardsPumpHandler
  299. {
  300. public EdwardsSwitchOffPumpHandler(EdwardsPump pump)
  301. : base(pump, "!P0", "")
  302. {
  303. Name = "Switch Off Pump";
  304. }
  305. public override bool HandleMessage(MessageBase msg, out bool handled)
  306. {
  307. if (base.HandleMessage(msg, out handled))
  308. {
  309. Device.NoteSetParaCompleted();
  310. }
  311. return true;
  312. }
  313. }
  314. public class EdwardsFastSwitchOffPumpHandler : EdwardsPumpHandler
  315. {
  316. public EdwardsFastSwitchOffPumpHandler(EdwardsPump pump)
  317. : base(pump, "!P2", "")
  318. {
  319. Name = "Switch Off Pump";
  320. }
  321. public override bool HandleMessage(MessageBase msg, out bool handled)
  322. {
  323. if (base.HandleMessage(msg, out handled))
  324. {
  325. Device.NoteSetParaCompleted();
  326. }
  327. return true;
  328. }
  329. }
  330. }