SiasunAlignerConnection.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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.Aligners.SiasunAligner
  8. {
  9. public class SiasunAlignerMessage : AsciiMessage
  10. {
  11. public string Data { get; set; }
  12. public string ErrorText { get; set; }
  13. }
  14. public class SiasunAlignerConnection : SerialPortConnectionBase
  15. {
  16. private string _cachedBuffer = string.Empty;
  17. public SiasunAlignerConnection(string portName, int baudRate = 19200, int dataBits = 8, Parity parity = Parity.None, StopBits stopBits = StopBits.One)
  18. : base(portName, baudRate, dataBits, parity, stopBits, "\r", true)
  19. {
  20. }
  21. public override bool SendMessage(byte[] message)
  22. {
  23. return base.SendMessage(message);
  24. }
  25. protected override MessageBase ParseResponse(string rawText)
  26. {
  27. SiasunAlignerMessage msg = new SiasunAlignerMessage();
  28. msg.RawMessage = rawText;
  29. if (rawText.Length <= 0)
  30. {
  31. LOG.Error($"empty response,");
  32. msg.IsFormatError = true;
  33. return msg;
  34. }
  35. rawText = rawText.Replace("\r", "").Replace("\n", "");
  36. if (rawText.Contains("_ERR"))
  37. {
  38. msg.IsError = true;
  39. var rewTextArray = rawText.Split(' ');
  40. msg.Data = rewTextArray[1];
  41. msg.IsComplete = true;
  42. }
  43. else if (rawText.Contains("_RDY"))
  44. {
  45. msg.Data = rawText.Replace("_RDY", "");
  46. msg.IsResponse = true;
  47. msg.IsAck = true;
  48. msg.IsComplete = true;
  49. }
  50. else
  51. {
  52. msg.Data = rawText;
  53. msg.IsResponse = true;
  54. }
  55. return msg;
  56. }
  57. }
  58. }