RevtechMatchMockPMA.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using System;
  2. using MECF.Framework.Simulator.Core.Driver;
  3. namespace Venus_Simulator.Devices
  4. {
  5. class RevtechMatchMockPMA : SocketDeviceSimulator
  6. {
  7. private const string EOF = "\n";
  8. private const char MSG_DELIMITER = '\n';
  9. private const string MOCKUP_PORT = "COM1";
  10. private const int MOCKUP_PORT2 = 5000;
  11. //private List<string> info = new List<string>();
  12. string info = "FAUTO,0,0,0,0,0,0,11,22,0,0,0,33,44,0,0,0,0";
  13. public RevtechMatchMockPMA() : base(MOCKUP_PORT2, -1, EOF, MSG_DELIMITER)
  14. {
  15. }
  16. protected override void ProcessUnsplitMessage(string message)
  17. {
  18. if (string.IsNullOrEmpty(message))
  19. throw new ArgumentException("Hardware command message is invalid");
  20. //string sRes = string.Empty;
  21. if (message.Contains(EOF))
  22. {
  23. message = message.Remove(message.Length - 1);
  24. }
  25. string[] msgs = message.Split('\n');
  26. foreach (string msg in msgs)
  27. {
  28. if (msg.Contains("MATCH:POS:C1"))
  29. {
  30. string newInfo = "";
  31. var c1 = msg.Split(' ')[1];
  32. string[] splits = info.Split(',');
  33. for (int i = 0; i < splits.Length; i++)
  34. {
  35. if (i == 8)
  36. {
  37. newInfo += c1;
  38. newInfo += ",";
  39. }
  40. else if (i == splits.Length - 1)
  41. {
  42. newInfo += splits[i];
  43. //newInfo += ",";
  44. }
  45. else
  46. {
  47. newInfo += splits[i];
  48. newInfo += ",";
  49. }
  50. }
  51. info = newInfo;
  52. }
  53. else if (msg.Contains("MATCH:POS:C2"))
  54. {
  55. string newInfo = "";
  56. var c2 = msg.Split(' ')[1];
  57. string[] splits = info.Split(',');
  58. for (int i = 0; i < splits.Length; i++)
  59. {
  60. if (i == 7)
  61. {
  62. newInfo += c2;
  63. newInfo += ",";
  64. }
  65. else if (i == splits.Length - 1)
  66. {
  67. newInfo += splits[i];
  68. //newInfo += ",";
  69. }
  70. else
  71. {
  72. newInfo += splits[i];
  73. newInfo += ",";
  74. }
  75. }
  76. info = newInfo;
  77. }
  78. else if (msg.Contains("MATCH:MODE"))
  79. {
  80. string newInfo = "";
  81. var mode = msg.Split(' ')[1];
  82. string[] splits = info.Split(',');
  83. for (int i = 0; i < splits.Length; i++)
  84. {
  85. if (i == 0)
  86. {
  87. newInfo += mode;
  88. newInfo += ",";
  89. }
  90. else if (i == splits.Length - 1)
  91. {
  92. newInfo += splits[i];
  93. //newInfo += ",";
  94. }
  95. else
  96. {
  97. newInfo += splits[i];
  98. newInfo += ",";
  99. }
  100. }
  101. info = newInfo;
  102. }
  103. if (msg.Contains("MATCH:FETCH?"))
  104. {
  105. if (!info.Contains("\n"))
  106. {
  107. info += "\n";
  108. }
  109. OnWriteMessage(info);
  110. }
  111. }
  112. }
  113. }
  114. }