123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- 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);
- }
- }
- }
- }
|