SkyPumpMockPMA.cs 1.9 KB

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