RevtechMatchMockPMC.cs 4.2 KB

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