using System; using System.Threading; using MECF.Framework.Simulator.Core.Driver; namespace EfemDualSimulator.Devices { class SkyPumpMockPMB : SerialPortDeviceSimulator { public enum SimPumpStatus { Open, Close, } public static SimPumpStatus _simPumpStatus; private const string EOF = "\r"; private const char MSG_DELIMITER = ' '; private const string MOCKUP_PORT = "COM33"; public SkyPumpMockPMB(string com) : base(com, -1, EOF, MSG_DELIMITER) { _simPumpStatus = SimPumpStatus.Open; } 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 "@00READ_RUN_PARA": if (_simPumpStatus == SimPumpStatus.Open) sRes = "@00RUN_PARA050308804314101000003\0\0hh\0\0\r\n"; else if (_simPumpStatus == SimPumpStatus.Close) sRes = "@00RUN_PARA050308804314101000003\0\0??\0\0\r\n"; break; case "@00CON_FDP_ON": _simPumpStatus = SimPumpStatus.Open; sRes = "@00FDP_ONOK" + "\0\r\n"; break; case "@00CON_FDP_OFF": _simPumpStatus = SimPumpStatus.Close; sRes = "@00FDP_OFFOK" + "\0\r\n"; break; default: break; } OnWriteMessage(sRes); } } } }