using System; using System.Threading; using MECF.Framework.Simulator.Core.Driver; namespace EfemDualSimulator.Devices { class EdwardsPumpMockPMA : SerialPortDeviceSimulator { public enum SimEdwardsPumpStatus { Open, Close, OnLine, OffLine, } public static SimEdwardsPumpStatus _simPumpStatus; public static SimEdwardsPumpStatus _simPumpControlStatus; private const string EOF = "\r"; private const char MSG_DELIMITER = ' '; private const string MOCKUP_PORT = "COM31"; public EdwardsPumpMockPMA(string com) : base(com, -1, EOF, MSG_DELIMITER) { _simPumpStatus = SimEdwardsPumpStatus.Close; _simPumpControlStatus = SimEdwardsPumpStatus.OffLine; } 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": _simPumpControlStatus = SimEdwardsPumpStatus.OnLine; sRes = "ERR 0" + "\r\n"; break; case "!C0": _simPumpControlStatus = SimEdwardsPumpStatus.OffLine; sRes = "ERR 0" + "\r\n"; break; case "!P1": if(_simPumpControlStatus == SimEdwardsPumpStatus.OnLine) { _simPumpStatus = SimEdwardsPumpStatus.Open; sRes = "ERR 0" + "\r\n"; } else { sRes = "ERR 5" + "\r\n"; } break; case "!P2": if (_simPumpControlStatus == SimEdwardsPumpStatus.OnLine) { _simPumpStatus = SimEdwardsPumpStatus.Close; sRes = "ERR 0" + "\r\n"; } else { sRes = "ERR 5" + "\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; case "?C": if (_simPumpControlStatus == SimEdwardsPumpStatus.OffLine) sRes = "0" + "\r\n"; else if (_simPumpControlStatus == SimEdwardsPumpStatus.OnLine) sRes = "1" + "\r\n"; else sRes = "0" + "\r\n"; break; default: break; } OnWriteMessage(sRes); } } } }