SMCChillerMockPMB.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System;
  2. using System.Threading;
  3. using MECF.Framework.Simulator.Core.Driver;
  4. using CyberX8_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 CyberX8_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. string module;//= PortName == "COM43" ? "PMA" : "PMB";
  54. switch (PortName)
  55. {
  56. case "COM43":
  57. case "COM53":
  58. module = "PMA";
  59. break;
  60. case "COM45":
  61. module = "PMB";
  62. break;
  63. case "COM86":
  64. module = "PMC";
  65. break;
  66. case "COM28":
  67. module = "PMD";
  68. break;
  69. default:
  70. module = "PMB";
  71. break;
  72. }
  73. double _OffsetTemp = SystemConfig.Instance.GetValue<double>($"{module}.Chiller.ChillerTemperatureOffset");
  74. SimulatorSystem.Instance.SetCoolantOutletTemp(module, temp / 10 + (int)_OffsetTemp);
  75. }
  76. }
  77. }