CommandPosition.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using StageController.M3H;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace StageController
  8. {
  9. /// <summary>
  10. /// 8.2.1 查询单独电机位置
  11. /// </summary>
  12. public class CommandPosition : CommandBase
  13. {
  14. private Motor m_motor;
  15. // 当前位置步长
  16. private int m_currentStep;
  17. // 边界
  18. private Border m_border;
  19. /// <summary>
  20. /// 查询单独电机位置 构造器
  21. /// </summary>
  22. /// <param name="axis">轴</param>
  23. public CommandPosition(Motor motor)
  24. {
  25. m_motor = motor;
  26. }
  27. /// <summary>
  28. ///
  29. /// </summary>
  30. /// <returns> @x! </returns>
  31. public override string Make()
  32. {
  33. return "@" + Enum.GetName(typeof(Motor), m_motor) + "!";
  34. }
  35. /// <summary>
  36. ///
  37. /// </summary>
  38. /// <param name="respons"> @Mx:X000A0=12345678,+12345678! </param>
  39. /// <returns></returns>
  40. public override bool Parse(string respons)
  41. {
  42. string motor = Enum.GetName(typeof(Motor), m_motor);
  43. string temp = "@M" + motor + ":" + motor.ToUpper();
  44. if (respons.Length != 30 || !respons.StartsWith(temp))
  45. {
  46. return false;
  47. }
  48. m_currentStep = int.Parse(respons.Substring(20, 9));
  49. m_border = (Border)Enum.ToObject(typeof(Border), int.Parse(respons.Substring(9, 1)));
  50. return true;
  51. }
  52. public Border CurrentBorder
  53. {
  54. get
  55. {
  56. return m_border;
  57. }
  58. }
  59. public int CurrentStep
  60. {
  61. get
  62. {
  63. return m_currentStep;
  64. }
  65. }
  66. }
  67. }