123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- using System;
- using MECF.Framework.Simulator.Core.Driver;
- namespace Venus_Simulator.Devices
- {
- class RevtechMatchMockPMA : SocketDeviceSimulator
- {
- private const string EOF = "\n";
- private const char MSG_DELIMITER = '\n';
- private const string MOCKUP_PORT = "COM1";
- private const int MOCKUP_PORT2 = 5000;
- //private List<string> info = new List<string>();
- string info = "FAUTO,0,0,0,0,0,0,11,22,0,0,0,33,44,0,0,0,0";
- public RevtechMatchMockPMA() : 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);
- }
- }
- }
- }
- }
|