AdTecGeneratorMock.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.Threading;
  3. using MECF.Framework.Simulator.Core.Driver;
  4. namespace EfemDualSimulator.Devices
  5. {
  6. class AdTecGeneratorMock : SerialPortDeviceSimulator
  7. {
  8. private const string EOF = "\r";
  9. private const char MSG_DELIMITER = '_';
  10. private const string MOCKUP_PORT = "COM51";
  11. public AdTecGeneratorMock() : base(MOCKUP_PORT, -1, EOF, MSG_DELIMITER)
  12. {
  13. }
  14. protected override void ProcessUnsplitMessage(string message)
  15. {
  16. if (string.IsNullOrEmpty(message))
  17. throw new ArgumentException("Hardware command message is invalid");
  18. string sRes = string.Empty;
  19. if (message.Contains(EOF))
  20. {
  21. message = message.Remove(message.Length - 1);
  22. }
  23. switch (message)
  24. {
  25. case "Q":
  26. sRes = "2000000 12345 23456 34567 45678";
  27. break;
  28. case "HS":
  29. sRes = "";
  30. break;
  31. default:
  32. break;
  33. }
  34. //string[] strs = message.Split(MSG_DELIMITER);
  35. //Thread.Sleep(2 * 1000);
  36. sRes += "\r";
  37. OnWriteMessage(sRes);
  38. }
  39. }
  40. }