EdwardsPumpMockPMA.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System;
  2. using System.Threading;
  3. using MECF.Framework.Simulator.Core.Driver;
  4. namespace EfemDualSimulator.Devices
  5. {
  6. class EdwardsPumpMockPMA : SerialPortDeviceSimulator
  7. {
  8. public enum SimEdwardsPumpStatus
  9. {
  10. Open,
  11. Close,
  12. OnLine,
  13. OffLine,
  14. }
  15. public static SimEdwardsPumpStatus _simPumpStatus;
  16. public static SimEdwardsPumpStatus _simPumpControlStatus;
  17. private const string EOF = "\r";
  18. private const char MSG_DELIMITER = ' ';
  19. private const string MOCKUP_PORT = "COM31";
  20. public EdwardsPumpMockPMA(string com) : base(com, -1, EOF, MSG_DELIMITER)
  21. {
  22. _simPumpStatus = SimEdwardsPumpStatus.Close;
  23. _simPumpControlStatus = SimEdwardsPumpStatus.OffLine;
  24. }
  25. protected override void ProcessUnsplitMessage(string message)
  26. {
  27. if (string.IsNullOrEmpty(message))
  28. throw new ArgumentException("Hardware command message is invalid");
  29. string[] strs = message.Split('\r');
  30. string sRes = string.Empty;
  31. foreach (var s2 in strs)
  32. {
  33. if (s2.Length < 1) continue;
  34. switch (s2)
  35. {
  36. case "/":
  37. strs = null;
  38. sRes = string.Empty;
  39. break;
  40. case "!C1":
  41. _simPumpControlStatus = SimEdwardsPumpStatus.OnLine;
  42. sRes = "ERR 0" + "\r\n";
  43. break;
  44. case "!C0":
  45. _simPumpControlStatus = SimEdwardsPumpStatus.OffLine;
  46. sRes = "ERR 0" + "\r\n";
  47. break;
  48. case "!P1":
  49. if(_simPumpControlStatus == SimEdwardsPumpStatus.OnLine)
  50. {
  51. _simPumpStatus = SimEdwardsPumpStatus.Open;
  52. sRes = "ERR 0" + "\r\n";
  53. }
  54. else
  55. {
  56. sRes = "ERR 5" + "\r\n";
  57. }
  58. break;
  59. case "!P2":
  60. if (_simPumpControlStatus == SimEdwardsPumpStatus.OnLine)
  61. {
  62. _simPumpStatus = SimEdwardsPumpStatus.Close;
  63. sRes = "ERR 0" + "\r\n";
  64. }
  65. else
  66. {
  67. sRes = "ERR 5" + "\r\n";
  68. }
  69. break;
  70. case "?P":
  71. if (_simPumpStatus == SimEdwardsPumpStatus.Open)
  72. sRes = "4" + "\r\n";
  73. else if (_simPumpStatus == SimEdwardsPumpStatus.Close)
  74. sRes = "0" + "\r\n";
  75. else
  76. sRes = "0" + "\r\n";
  77. break;
  78. case "?C":
  79. if (_simPumpControlStatus == SimEdwardsPumpStatus.OffLine)
  80. sRes = "0" + "\r\n";
  81. else if (_simPumpControlStatus == SimEdwardsPumpStatus.OnLine)
  82. sRes = "1" + "\r\n";
  83. else
  84. sRes = "0" + "\r\n";
  85. break;
  86. default:
  87. break;
  88. }
  89. OnWriteMessage(sRes);
  90. }
  91. }
  92. }
  93. }