SkyPumpMock.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using System.IO.Ports;
  3. using System.Threading;
  4. using MECF.Framework.Simulator.Core.Driver;
  5. namespace EfemDualSimulator.Devices
  6. {
  7. class SkyPumpMock : SerialPortDeviceSimulator
  8. {
  9. public enum SimPumpStatus
  10. {
  11. Open,
  12. Close,
  13. }
  14. public static SimPumpStatus _simPumpStatus;
  15. private const string EOF = "\r\n";
  16. private const char MSG_DELIMITER = ' ';
  17. private const string MOCKUP_PORT = "COM33";
  18. public SkyPumpMock() : base(MOCKUP_PORT, -1, EOF, MSG_DELIMITER,true)
  19. {
  20. _simPumpStatus = SimPumpStatus.Close;
  21. }
  22. protected override void ProcessUnsplitMessage(string message)
  23. {
  24. if (string.IsNullOrEmpty(message))
  25. throw new ArgumentException("Hardware command message is invalid");
  26. string[] strs = message.Split('\r');
  27. string sRes = string.Empty;
  28. foreach (var s2 in strs)
  29. {
  30. if (s2.Length < 1) continue;
  31. switch (s2)
  32. {
  33. case "@00READ_RUN_PARA":
  34. if (_simPumpStatus == SimPumpStatus.Open)
  35. sRes = "@00RUN_PARA050308804314101000003\0\0hh\0\0\r\n";
  36. else if (_simPumpStatus == SimPumpStatus.Close)
  37. sRes = "@00RUN_PARA050308804314101000003\0\0??\0\0\r\n";
  38. break;
  39. case "@00CON_FDP_ON":
  40. _simPumpStatus = SimPumpStatus.Open;
  41. sRes = "@00FDP_ONOK" + "\0\r\n";
  42. break;
  43. case "@00CON_FDP_OFF":
  44. _simPumpStatus = SimPumpStatus.Close;
  45. sRes = "@00FDP_OFFOK" + "\0\r\n";
  46. break;
  47. default:
  48. break;
  49. }
  50. OnWriteMessage(sRes);
  51. }
  52. }
  53. }
  54. }