AdTecGeneratorMockPMB.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System;
  2. using System.Threading;
  3. using MECF.Framework.Simulator.Core.Driver;
  4. namespace EfemDualSimulator.Devices
  5. {
  6. class AdTecGeneratorMockPMB : SerialPortDeviceSimulator
  7. {
  8. public enum GeneratorStatus
  9. {
  10. Unknown,
  11. OFF,
  12. ON,
  13. ERROR
  14. }
  15. public GeneratorStatus _simGeneratorStatus;
  16. private const string EOF = "\r";
  17. private const char MSG_DELIMITER = '_';
  18. private const string MOCKUP_PORT = "COM35";
  19. public AdTecGeneratorMockPMB(string com) : base(com, -1, EOF, MSG_DELIMITER)
  20. {
  21. _simGeneratorStatus = GeneratorStatus.Unknown;
  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 sRes = string.Empty;
  28. if (message.Contains(EOF))
  29. {
  30. message = message.Remove(message.Length - 1);
  31. }
  32. switch (message)
  33. {
  34. case "Q":
  35. if (_simGeneratorStatus == GeneratorStatus.ON)
  36. {
  37. sRes = "2010000 12345 00900 00100 45678\r";
  38. }
  39. else if (_simGeneratorStatus == GeneratorStatus.OFF)
  40. {
  41. sRes = "2000000 12345 00000 00000 45678\r";
  42. }
  43. break;
  44. case "G":
  45. _simGeneratorStatus = GeneratorStatus.ON;
  46. sRes = "\r";
  47. break;
  48. case "S":
  49. _simGeneratorStatus = GeneratorStatus.OFF;
  50. sRes = "\r";
  51. break;
  52. default:
  53. break;
  54. }
  55. //string[] strs = message.Split(MSG_DELIMITER);
  56. //Thread.Sleep(2 * 1000);
  57. sRes += "\r";
  58. OnWriteMessage(sRes);
  59. }
  60. }
  61. }