PumpMagpowerConnection.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Security.Permissions;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using Aitex.Core.RT.Log;
  8. using MECF.Framework.Common.Communications;
  9. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.TurboPumps.Pfeiffer
  10. {
  11. public class MagpowerMessage : AsciiMessage
  12. {
  13. public string DeviceAddress { get; set; }
  14. //public string Action { get; set; }
  15. //public string Parameter { get; set; }
  16. //public int DataLength { get; set; }
  17. public string Data { get; set; }
  18. public string ErrorText { get; set; }
  19. }
  20. public class PumpMagpowerConnection : SerialPortConnectionBase
  21. {
  22. public PumpMagpowerConnection(string portName) : base(portName)
  23. {
  24. }
  25. //#adr,ok
  26. //#adr,nnnnn,sssss,00000,0,ccccc,eeeee,ddddd,pppp,qqqq,jj,kk,lll,mmm
  27. //#adr,nnnnn rpm
  28. protected override MessageBase ParseResponse(string rawText)
  29. {
  30. MagpowerMessage msg = new MagpowerMessage();
  31. msg.RawMessage = rawText;
  32. if (rawText.Length <= 4)
  33. {
  34. LOG.Error($"response length check failed, " + rawText);
  35. msg.IsFormatError = true;
  36. return msg;
  37. }
  38. msg.MessagePart = new string[2];
  39. int seperatorIndex = rawText.IndexOf(',');
  40. if(seperatorIndex != 4)
  41. {
  42. LOG.Error($"response format check failed, " + rawText);
  43. msg.IsFormatError = true;
  44. return msg;
  45. }
  46. msg.MessagePart[0] = rawText.Substring(1, 3); //device address
  47. msg.MessagePart[1] = rawText.Substring(5, rawText.Length - 6); //data
  48. msg.DeviceAddress = msg.MessagePart[0];
  49. msg.Data = msg.MessagePart[1];
  50. if (msg.Data.Contains("Err"))
  51. {
  52. msg.IsError = true;
  53. }
  54. msg.IsResponse = true;
  55. msg.IsAck = true;
  56. msg.IsComplete = true;
  57. return msg;
  58. }
  59. }
  60. }