SMCChillerMockPMB.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Threading;
  3. using MECF.Framework.Simulator.Core.Driver;
  4. using Venus_Simulator.Instances;
  5. using Aitex.Core.RT.SCCore;
  6. using MECF.Framework.Common.SCCore;
  7. using MECF.Framework.Common.DataCenter;
  8. using Aitex.Core.Util;
  9. using System.IO;
  10. namespace Venus_Simulator.Devices
  11. {
  12. class SMCChillerMock : SerialPortDeviceSimulator
  13. {
  14. public enum SMCChillerStatus
  15. {
  16. Open,
  17. Close,
  18. }
  19. public static SMCChillerStatus _simPumpStatus;
  20. private const string EOF = "\r\n";
  21. private const char MSG_DELIMITER = ' ';
  22. //private const string MOCKUP_PORT = "COM43";
  23. public SMCChillerMock(string port) : base(port, -1, EOF, MSG_DELIMITER)
  24. {
  25. _simPumpStatus = SMCChillerStatus.Close;
  26. }
  27. protected override void ProcessUnsplitMessage(string message)
  28. {
  29. if (string.IsNullOrEmpty(message))
  30. throw new ArgumentException("Hardware command message is invalid");
  31. string[] separatingStrings = { EOF };
  32. string[] msgs = message.Trim().Split(separatingStrings, System.StringSplitOptions.RemoveEmptyEntries);
  33. foreach (var msg in msgs)
  34. {
  35. if(msg.StartsWith(":0106000B"))
  36. {
  37. int temp = Convert.ToInt32(msg.Substring(9, 8), 16);
  38. Console.WriteLine($"Chiller Set Temp: {temp}");
  39. SetTemp(temp);
  40. }
  41. else if(msg.StartsWith(":0106000C0001"))
  42. {
  43. _simPumpStatus = SMCChillerStatus.Open;
  44. }
  45. else if(msg.StartsWith(":0106000C0000"))
  46. {
  47. _simPumpStatus = SMCChillerStatus.Close;
  48. }
  49. }
  50. }
  51. void SetTemp(int temp)
  52. {
  53. //Singleton<SystemConfigManager>.Instance.Initialize(PathManager.GetCfgDir() + "System.sccfg");
  54. string module = PortName == "COM43" ? "PMA" : "PMB";
  55. //double _OffsetTemp = SC.GetValue<double>($"{module}.Chiller.ChillerTemperatureOffset");
  56. double _OffsetTemp = SystemConfig.Instance.GetValue<double>($"{module}.Chiller.ChillerTemperatureOffset");
  57. //double offset = (double)QueryDataClient.Instance.Service.GetConfig($"{module}.Chiller.ChillerTemperatureOffset");
  58. SimulatorSystem.Instance.SetCoolantOutletTemp(module, temp / 10 + (int)_OffsetTemp);
  59. }
  60. }
  61. }