using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using System.Windows.Documents; using MECF.Framework.Simulator.Core.Driver; namespace Venus_Simulator.Devices { class RevtechMatchMockPMD : SocketDeviceSimulator { private const string EOF = "\n"; private const char MSG_DELIMITER = '\n'; private const string MOCKUP_PORT = "COM76"; //private List info = new List(); private const int MOCKUP_PORT2 = 5003; string info = "FAUTO,0,0,0,0,0,0,11,22,0,0,0,33,44,0,0,0,0"; public RevtechMatchMockPMD() : base(MOCKUP_PORT2, -1, EOF, MSG_DELIMITER) { } protected override void ProcessUnsplitMessage(string message) { if (string.IsNullOrEmpty(message)) throw new ArgumentException("Hardware command message is invalid"); //string sRes = string.Empty; if (message.Contains(EOF)) { message = message.Remove(message.Length - 1); } string[] msgs = message.Split('\n'); foreach (string msg in msgs) { if (msg.Contains("MATCH:POS:C1")) { string newInfo = ""; var c1 = msg.Split(' ')[1]; string[] splits = info.Split(','); for (int i = 0; i < splits.Length; i++) { if (i == 8) { newInfo += c1; newInfo += ","; } else if (i == splits.Length - 1) { newInfo += splits[i]; //newInfo += ","; } else { newInfo += splits[i]; newInfo += ","; } } info = newInfo; } else if (msg.Contains("MATCH:POS:C2")) { string newInfo = ""; var c2 = msg.Split(' ')[1]; string[] splits = info.Split(','); for (int i = 0; i < splits.Length; i++) { if (i == 7) { newInfo += c2; newInfo += ","; } else if (i == splits.Length - 1) { newInfo += splits[i]; //newInfo += ","; } else { newInfo += splits[i]; newInfo += ","; } } info = newInfo; } else if (msg.Contains("MATCH:MODE")) { string newInfo = ""; var mode = msg.Split(' ')[1]; string[] splits = info.Split(','); for (int i = 0; i < splits.Length; i++) { if (i == 0) { newInfo += mode; newInfo += ","; } else if (i == splits.Length - 1) { newInfo += splits[i]; //newInfo += ","; } else { newInfo += splits[i]; newInfo += ","; } } info = newInfo; } if (msg.Contains("MATCH:FETCH?")) { if (!info.Contains("\n")) { info += "\n"; } OnWriteMessage(info); } } } } }