FfuMayAirConnection.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using MECF.Framework.Common.Communications;
  2. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.FFUs.MayAir
  3. {
  4. public class FfuMayAirMessage : BinaryMessage
  5. {
  6. public byte Prefix { get; set; }
  7. public byte Action { get; set; }
  8. public byte Command { get; set; }
  9. public byte DeviceAddress { get; set; }
  10. public byte GroupAddress { get; set; }
  11. public byte Data1 { get; set; }
  12. public byte Data2 { get; set; }
  13. }
  14. public class FfuMayAirConnection : SerialPortConnectionBase
  15. {
  16. public FfuMayAirConnection(string portName) : base(portName)
  17. {
  18. }
  19. protected override MessageBase ParseResponse(byte[] rawMessage)
  20. {
  21. FfuMayAirMessage msg = new FfuMayAirMessage();
  22. //msg.RawMessage = rawText;
  23. //if (rawText.Length <= 14)
  24. //{
  25. // LOG.Error($"text length check failed, " + rawText);
  26. // msg.IsFormatError = true;
  27. // return msg;
  28. //}
  29. //msg.MessagePart = new string[6];
  30. //msg.MessagePart[0] = rawText.Substring(0, 3); //device address
  31. //msg.MessagePart[1] = rawText.Substring(3, 2); // action
  32. //msg.MessagePart[2] = rawText.Substring(5, 3); //parameter
  33. //msg.MessagePart[3] = rawText.Substring(8, 2); //length
  34. //if (!int.TryParse(msg.MessagePart[3], out int length))
  35. //{
  36. // LOG.Error($"text {msg.MessagePart[3]} not valid, " + rawText);
  37. // msg.IsFormatError = true;
  38. // return msg;
  39. //}
  40. //msg.MessagePart[4] = rawText.Substring(10, length); //data
  41. //msg.MessagePart[5] = rawText.Substring(10 + length, 3);
  42. //if (!int.TryParse(msg.MessagePart[5], out int sum))
  43. //{
  44. // LOG.Error($"text {msg.MessagePart[5]} not valid, " + rawText);
  45. // msg.IsFormatError = true;
  46. // return msg;
  47. //}
  48. //int checkSum = 0;
  49. //string checkText = rawText.Substring(0, rawText.Length - 3 - 1);
  50. // foreach (var item in checkText)
  51. // {
  52. // checkSum += (int)item;
  53. // }
  54. //if (checkSum % 256 != sum)
  55. //{
  56. // LOG.Error($"check sum failed, " + rawText);
  57. // msg.IsFormatError = true;
  58. // return msg;
  59. //}
  60. //msg.DeviceAddress = msg.MessagePart[0];
  61. //msg.Action = msg.MessagePart[1];
  62. //msg.Parameter = msg.MessagePart[2];
  63. //msg.DataLength = length;
  64. //msg.Data = msg.MessagePart[4];
  65. //if (msg.Data == "NO_DEF" || msg.Data=="_RANGE" || msg.Data=="_LOGIC")
  66. //{
  67. // msg.IsError = true;
  68. //}
  69. msg.IsResponse = true;
  70. msg.IsAck = true;
  71. msg.IsComplete = true;
  72. return msg;
  73. }
  74. }
  75. }