VATS651Connection.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System.Collections.Generic;
  2. using System.IO.Ports;
  3. using System.Linq;
  4. using System.Text;
  5. using Aitex.Core.RT.Log;
  6. using MECF.Framework.Common.Communications;
  7. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.ThrottleValves.VAT
  8. {
  9. public class VATS651Message : AsciiMessage
  10. {
  11. public string Data { get; set; }
  12. public string ErrorText { get; set; }
  13. }
  14. public class VATS651Connection : SerialPortConnectionBase
  15. {
  16. private static string _endLine = "\r\n";
  17. private string _cachedBuffer = string.Empty;
  18. public VATS651Connection(string portName, int baudRate = 9600, int dataBits = 7, Parity parity = Parity.Even, StopBits stopBits = StopBits.One)
  19. : base(portName, baudRate, dataBits, parity, stopBits, _endLine, true)
  20. {
  21. }
  22. protected override MessageBase ParseResponse(string rawText)
  23. {
  24. VATS651Message msg = new VATS651Message();
  25. msg.RawMessage = rawText;
  26. if (rawText.Length <= 0)
  27. {
  28. LOG.Error($"empty response,");
  29. msg.IsFormatError = true;
  30. return msg;
  31. }
  32. rawText = rawText.Replace("\r", "");
  33. rawText = rawText.Replace("\n", "");
  34. if (rawText.Length <= 1)
  35. {
  36. LOG.Error($"too short response,");
  37. msg.IsFormatError = true;
  38. return msg;
  39. }
  40. if (rawText.Contains("E:"))
  41. {
  42. msg.IsError = true;
  43. msg.Data = rawText.Substring(2, rawText.Length - 2); ;
  44. }
  45. else
  46. {
  47. msg.Data = rawText;
  48. msg.IsAck = true;
  49. }
  50. return msg;
  51. }
  52. }
  53. }