AIRSYSChillerMock.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 AIRSYSChillerMock : SerialPortDeviceSimulator
  13. {
  14. public enum AIRSYSChillerStatus
  15. {
  16. Open,
  17. Close,
  18. }
  19. public static AIRSYSChillerStatus _simPumpStatus;
  20. private const string EOF = "\r";
  21. private const char MSG_DELIMITER = ' ';
  22. //private const string MOCKUP_PORT = "COM43";
  23. private int _temperature = 0;
  24. public AIRSYSChillerMock(string port) : base(port, -1, EOF, MSG_DELIMITER)
  25. {
  26. _simPumpStatus = AIRSYSChillerStatus.Close;
  27. }
  28. protected override void ProcessUnsplitMessage(string message)
  29. {
  30. if (string.IsNullOrEmpty(message))
  31. throw new ArgumentException("Hardware command message is invalid");
  32. string sRes = string.Empty;
  33. string[] separatingStrings = { EOF };
  34. string[] msgs = message.Trim().Split(separatingStrings, System.StringSplitOptions.RemoveEmptyEntries);
  35. foreach (var msg in msgs)
  36. {
  37. if (msg.StartsWith("AA90"))
  38. {
  39. _simPumpStatus = AIRSYSChillerStatus.Open;
  40. sRes = "AA90\r";
  41. int temp = Convert.ToInt32(msg.Substring(9, 8), 16);
  42. SetTemp(temp);
  43. }
  44. else if(msg.StartsWith("AA91"))
  45. {
  46. _simPumpStatus = AIRSYSChillerStatus.Close;
  47. sRes = "AA91\r";
  48. }
  49. else if (msg.StartsWith("AA42"))
  50. {
  51. //QUERY STATUS
  52. _simPumpStatus = AIRSYSChillerStatus.Open;
  53. sRes = "AA4200DE\r";
  54. }
  55. else if (msg.StartsWith("AA10"))
  56. {
  57. //QUERY TEMPERATURE
  58. sRes = string.Format("AA10{0:X4}\r", _temperature);
  59. }
  60. else if (msg.StartsWith("AAB0"))
  61. {
  62. //Set Temperature
  63. _temperature = Int32.Parse(msg.Substring(4, 4), System.Globalization.NumberStyles.HexNumber);
  64. sRes = "AAB0\r";
  65. }
  66. }
  67. OnWriteMessage(sRes);
  68. }
  69. void SetTemp(int temp)
  70. {
  71. string module = PortName == "COM47" ? "PMA" : "PMB";
  72. double _OffsetTemp = SystemConfig.Instance.GetValue<double>($"{module}.Chiller.ChillerTemperatureOffset");
  73. SimulatorSystem.Instance.SetCoolantOutletTemp(module, temp / 10 + (int)_OffsetTemp);
  74. }
  75. }
  76. }