123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- using System;
- using System.Threading;
- using MECF.Framework.Simulator.Core.Driver;
- namespace EfemDualSimulator.Devices
- {
- class AdTecGeneratorMockPMB : 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 = "COM35";
- public AdTecGeneratorMockPMB(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);
- }
- }
- }
|