using System; using System.Threading; using MECF.Framework.Simulator.Core.Driver; namespace EfemDualSimulator.Devices { class AdTecGeneratorMockPMA : SerialPortDeviceSimulator { public enum GeneratorStatus { Unknown, OFF, ON, ERROR } public GeneratorStatus _simGeneratorStatus; private const string EOF = "\r"; private const char MSG_DELIMITER = '_'; private const string MOCKUP_PORT = "COM37"; public AdTecGeneratorMockPMA(string com) : base(com, -1, EOF, MSG_DELIMITER) { _simGeneratorStatus = GeneratorStatus.Unknown; } 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); } switch (message) { case "Q": if (_simGeneratorStatus == GeneratorStatus.ON) { sRes = "2010000 12345 00900 00100 45678\r"; } else if (_simGeneratorStatus == GeneratorStatus.OFF) { sRes = "2000000 12345 00000 00000 45678\r"; } break; case "G": _simGeneratorStatus = GeneratorStatus.ON; sRes = "\r"; break; case "S": _simGeneratorStatus = GeneratorStatus.OFF; sRes = "\r"; break; default: break; } //string[] strs = message.Split(MSG_DELIMITER); //Thread.Sleep(2 * 1000); sRes += "\r"; OnWriteMessage(sRes); } } }