EdwardsPumpMockPMB.cs 2.5 KB

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