SimChillerSmcHRZ.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Timers;
  6. using Aitex.Core.UI.Control;
  7. using MECF.Framework.Common.Utilities;
  8. using MECF.Framework.Simulator.Core.Driver;
  9. namespace MECF.Framework.Simulator.Core.Chillers
  10. {
  11. class SimChillerSmcHRZ : SerialPortDeviceSimulator
  12. {
  13. Random _rd = new Random();
  14. private object _locker = new object();
  15. public bool IsNoResponse { get; internal set; }
  16. public bool IsRemote { get; internal set; }
  17. public bool IsRun { get; internal set; }
  18. public bool IsFault { get; internal set; }
  19. public string TempSetPoint { get; internal set; }
  20. public float TempFeedback { get; internal set; }
  21. public SimChillerSmcHRZ(string port)
  22. : base(port, -1, "\r\n", ' ', true)
  23. {
  24. }
  25. static class Constant
  26. {
  27. public const string Start = ":";
  28. public const string End = "\r\n";
  29. public const string SlaveAddress = "01";
  30. public const string Function_R_M = "17";
  31. public const string Function_W_S = "17";
  32. public const string Function_W_M = "17";
  33. public const string Function_RW_M = "17";
  34. public const string Data_Address_GetTemp = "0000";
  35. public const string Data_Address_GetPress = "0002";
  36. public const string Data_Address_GetElec = "0003";
  37. public const string Data_Address_Status1 = "0004";
  38. public const string Data_Address_Alarm1 = "0005";
  39. public const string Data_Address_Alarm2 = "0006";
  40. public const string Data_Address_Alarm3 = "0007";
  41. public const string Data_Address_Status2 = "0009";
  42. public const string Data_Address_SetTemp = "000B";
  43. public const string Data_Address_SetRun = "000C";
  44. public const string SET_ON = SlaveAddress + Function_W_S + Data_Address_SetRun + "0001";
  45. public const string SET_OFF = SlaveAddress + Function_W_S + Data_Address_SetRun + "0000";
  46. public const string SET_TEMP = SlaveAddress + Function_W_S + Data_Address_SetTemp;
  47. public const string GET_ALL = SlaveAddress + Function_R_M + Data_Address_GetTemp + "000B";
  48. }
  49. protected override void ProcessUnsplitMessage(string message)
  50. {
  51. //if (IsFault)
  52. //{
  53. // //OnWriteMessage($"{Constant.SlaveAddress}97");
  54. // //return;
  55. //}
  56. //读,默认7个全返回
  57. if (message.Substring(9, 4) != "0000")
  58. {
  59. string data = $"{Constant.SlaveAddress}{ Constant.Function_R_M}0E";
  60. for (int i = 0; i < 7; i++)
  61. {
  62. data += $"0000";
  63. }
  64. OnWriteMessage(GetResponseText(data));
  65. }
  66. //写
  67. }
  68. public string GetResponseText(string str)
  69. {
  70. return ":01171A00F900000000FFFF006600300040000000000000000000C8000039\r\n";
  71. //return ":" + str + ModbusUtility.CalculateLrc(ModbusUtility.HexToBytes(str)).ToString("X2") + "\r\n";
  72. }
  73. internal void SetTemp()
  74. {
  75. TempFeedback = float.Parse(TempSetPoint);
  76. }
  77. }
  78. }