using System; using System.Threading; using MECF.Framework.Simulator.Core.Driver; namespace EfemDualSimulator.Devices { class EdwardsPumpMockPMB : SerialPortDeviceSimulator { public enum SimEdwardsPumpStatus { Open, Close, OnLine, OffLine, } public static SimEdwardsPumpStatus _simPumpStatus; private const string EOF = "\r"; private const char MSG_DELIMITER = ' '; private const string MOCKUP_PORT = "COM33"; public EdwardsPumpMockPMB(string com) : base(com, -1, EOF, MSG_DELIMITER) { _simPumpStatus = SimEdwardsPumpStatus.Close; } protected override void ProcessUnsplitMessage(string message) { if (string.IsNullOrEmpty(message)) throw new ArgumentException("Hardware command message is invalid"); string[] strs = message.Split('\r'); string sRes = string.Empty; foreach (var s2 in strs) { if (s2.Length < 1) continue; switch (s2) { case "/": strs = null; sRes = string.Empty; break; case "!C1": _simPumpStatus = SimEdwardsPumpStatus.OnLine; sRes = "ERR 0" + "\r\n"; break; case "!C0": _simPumpStatus = SimEdwardsPumpStatus.OffLine; sRes = "ERR 0" + "\r\n"; break; case "!P1": _simPumpStatus = SimEdwardsPumpStatus.Open; sRes = "ERR 0" + "\r\n"; break; case "!P2": _simPumpStatus = SimEdwardsPumpStatus.Close; sRes = "ERR 0" + "\r\n"; break; case "?P": if (_simPumpStatus == SimEdwardsPumpStatus.Open) sRes = "4" + "\r\n"; else if (_simPumpStatus == SimEdwardsPumpStatus.Close) sRes = "0" + "\r\n"; else sRes = "0" + "\r\n"; break; default: break; } OnWriteMessage(sRes); } } } }