Hirata.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. using MECF.Framework.Simulator.Core.Driver;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8. namespace athosSimulator.LoadPort
  9. {
  10. public class Hirata : SerialPortDeviceSimulator
  11. {
  12. //public GeneratorStatus _simGeneratorStatus;
  13. private const string EOF = "\r";
  14. private const char MSG_DELIMITER = ' ';
  15. private object _lock = new object();
  16. public Hirata(string portname) : base(portname, -1, EOF, MSG_DELIMITER)
  17. {
  18. }
  19. public override bool IsEnabled => base.IsEnabled;
  20. public override bool IsConnected => base.IsConnected;
  21. public override bool Equals(object obj)
  22. {
  23. return base.Equals(obj);
  24. }
  25. public override int GetHashCode()
  26. {
  27. return base.GetHashCode();
  28. }
  29. public override string ToString()
  30. {
  31. return base.ToString();
  32. }
  33. //走这里
  34. protected override void ProcessUnsplitMessage(string command)
  35. {
  36. //if (command.Contains(EOF))
  37. //{
  38. // char eof= EOF.ToCharArray()[0];
  39. // string[] sstr= command.Split(eof);
  40. //}
  41. //else
  42. lock(_lock)
  43. {
  44. if (command.Contains("SET:"))
  45. {
  46. //直接返回一样的
  47. OnWriteMessage(command);
  48. }
  49. if (command.Contains("GET:"))
  50. {
  51. if (command.Contains("STAS"))
  52. {
  53. OnWriteMessage("0000GET:STAS/00100010101000000000;**"+ EOF);
  54. }
  55. if (command.Contains("MAPR"))
  56. {
  57. //全空
  58. //OnWriteMessage("0000GET:MAPR/00000000000000000000000000;**"+ EOF);
  59. //全有
  60. OnWriteMessage("0000GET:MAPR/1111111111111111111111111;**"+ EOF);
  61. }
  62. }
  63. if (command.Contains("MOV:"))
  64. {
  65. OnWriteMessage(command);
  66. Thread.Sleep(6000);
  67. OnWriteMessage(command.Replace("MOV", "INF"));
  68. }
  69. }
  70. }
  71. protected override void ProcessUnsplitMessage(byte[] message)
  72. {
  73. string command = string.Empty;
  74. foreach (byte _ch in message)
  75. {
  76. //当不是截断符时
  77. if (_ch.ToString() != EOF)
  78. {
  79. command += _ch.ToString();
  80. }
  81. else
  82. {
  83. command += _ch.ToString();
  84. if (command.Contains("SET"))
  85. {
  86. //直接返回一样的
  87. OnWriteMessage(command);
  88. }
  89. if (command.Contains("GET"))
  90. {
  91. if (command.Contains("STAS"))
  92. {
  93. OnWriteMessage("0000GET:STAS/00100010101000000000;**");
  94. }
  95. if (command.Contains("MAPR"))
  96. {
  97. OnWriteMessage("0000GET:MAPR/00000000000000000000000000;**");
  98. }
  99. }
  100. if (command.Contains("MOV"))
  101. {
  102. OnWriteMessage(command);
  103. command.Replace("MOV","INF");
  104. Thread.Sleep(6000);
  105. OnWriteMessage(command);
  106. }
  107. command = string.Empty;
  108. }
  109. }
  110. }
  111. protected override void AddCommandHandler(string command, Action<string> handler)
  112. {
  113. base.AddCommandHandler(command, handler);
  114. }
  115. protected override void CommandNotRecognized(string msg)
  116. {
  117. base.CommandNotRecognized(msg);
  118. }
  119. protected override void OnErrorMessage(string message)
  120. {
  121. base.OnErrorMessage(message);
  122. }
  123. protected override void ProcessWriteMessage(string msg)
  124. {
  125. base.ProcessWriteMessage(msg);
  126. }
  127. protected override void ProcessWriteMessage(byte[] msg)
  128. {
  129. base.ProcessWriteMessage(msg);
  130. }
  131. }
  132. }