Analysiser.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using ivf_tl_Entity.GlobalEnums;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace ivf_tl_Entity.ComEntitys
  8. {
  9. public class Analysiser
  10. {
  11. /// <summary>
  12. /// 解析E方
  13. /// </summary>
  14. /// <param name="customProtocol"></param>
  15. /// <returns></returns>
  16. public static int ParseEEPROMPulse(byte[] arg)
  17. {
  18. if (!arg.Any()) return -1;
  19. byte[] temp = { arg[4], arg[5], arg[6], arg[7] };
  20. if (!BitConverter.IsLittleEndian)
  21. Array.Reverse(temp);
  22. return BitConverter.ToInt32(temp, 0);
  23. }
  24. /// <summary>
  25. /// 握手指令解析
  26. /// </summary>
  27. /// <param name="arg"></param>
  28. /// <returns></returns>
  29. public static int ParseShakeHandsCommand(byte[] arg)
  30. {
  31. if (arg.Any()) return Convert.ToInt32(arg[2]);
  32. return -1;
  33. }
  34. /// <summary>
  35. /// 舱门状态
  36. /// </summary>
  37. /// <param name="bs"></param>
  38. /// <returns></returns>
  39. public static State ParseDoorStatus(byte[] arg)
  40. {
  41. if (!arg.Any()) return State.未知;
  42. return arg[4] == 0x01 ? State.打开 : State.关闭;
  43. }
  44. /// <summary>
  45. /// 温度解析
  46. /// </summary>
  47. /// <param name="bs"></param>
  48. /// <returns></returns>
  49. public static decimal ParseTemperatureCommand(byte[] arg)
  50. {
  51. if (!arg.Any()) return -1m;
  52. byte[] temp = { arg[5], arg[4] };
  53. if (!BitConverter.IsLittleEndian)
  54. Array.Reverse(temp);
  55. int num = BitConverter.ToInt16(temp);
  56. var result = Math.Round(num / 100.00m, 2, MidpointRounding.AwayFromZero);
  57. return result;
  58. }
  59. /// <summary>
  60. /// 气压解析
  61. /// </summary>
  62. /// <param name="arg"></param>
  63. /// <returns></returns>
  64. public static decimal ParsePressureCommand(byte[] arg)
  65. {
  66. if (!arg.Any()) return -1m;
  67. byte[] temp = { arg[5], arg[4] };
  68. if (!BitConverter.IsLittleEndian)
  69. Array.Reverse(temp);
  70. int num = BitConverter.ToInt16(temp);
  71. return (decimal)num;
  72. }
  73. /// <summary>
  74. /// 仪器温度1解析
  75. /// </summary>
  76. /// <param name="customProtocol"></param>
  77. /// <returns></returns>
  78. public static decimal ParseTLTemperature1Command(byte[] arg)
  79. {
  80. if (!arg.Any()) return -1m;
  81. byte[] temp = { arg[7], arg[6] };
  82. if (!BitConverter.IsLittleEndian)
  83. Array.Reverse(temp);
  84. int num = BitConverter.ToInt16(temp);
  85. return Math.Round(num / 100.00m, 2, MidpointRounding.AwayFromZero);
  86. }
  87. /// <summary>
  88. /// 仪器温度2解析
  89. /// </summary>
  90. /// <param name="customProtocol"></param>
  91. /// <returns></returns>
  92. public static decimal ParseTLTemperature2Command(byte[] arg)
  93. {
  94. if (!arg.Any()) return -1m;
  95. byte[] temp = { arg[9], arg[8] };
  96. if (!BitConverter.IsLittleEndian)
  97. Array.Reverse(temp);
  98. int num = BitConverter.ToInt16(temp);
  99. return Math.Round(num / 100.00m, 2, MidpointRounding.AwayFromZero);
  100. }
  101. /// <summary>
  102. /// 当前电机位置解析
  103. /// </summary>
  104. /// <param name="customProtocol"></param>
  105. /// <returns></returns>
  106. public static int ParseCurrentMotor(byte[] arg)
  107. {
  108. if (!arg.Any()) return -1;
  109. byte[] temp = { arg[7], arg[6], arg[5], arg[4] };
  110. if (!BitConverter.IsLittleEndian)
  111. Array.Reverse(temp);
  112. return BitConverter.ToInt32(temp, 0);
  113. }
  114. }
  115. }