CommandMoveByStep.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. #if true
  8. namespace StageController
  9. {
  10. /// <summary>
  11. /// 4.1 电脑控制电机按步运行指令
  12. /// </summary>
  13. public class CommandMoveByStep : CommandBase
  14. {
  15. private M3HAxisType m_axis;
  16. private int m_steps;
  17. private string m_speed;
  18. public CommandMoveByStep(M3HAxisType axis, int steps, int speed)
  19. {
  20. m_axis = axis;
  21. m_steps = steps;
  22. Speed = speed;
  23. }
  24. public int Speed
  25. {
  26. set
  27. {
  28. if (value.ToString().Length > 3)
  29. {
  30. m_speed = "999";
  31. return;
  32. }
  33. m_speed = "000".Substring(0, 3 - value.ToString().Length) + value;
  34. }
  35. }
  36. public override string Make()
  37. {
  38. return buildCmd() + "!";
  39. }
  40. public override bool Parse(string response)
  41. {
  42. string tmpRes = "@" + Enum.GetName(typeof(M3HAxisType), m_axis) + m_speed;
  43. if (response.Length == 15 && response.StartsWith(tmpRes))
  44. {
  45. return true;
  46. }
  47. return false;
  48. }
  49. private string buildCmd()
  50. {
  51. string mark = "+";
  52. int tmpStep = m_steps;
  53. if (m_steps < 0)
  54. {
  55. mark = "-";
  56. tmpStep = -m_steps;
  57. }
  58. string stepStr = tmpStep.ToString("D8");
  59. return "@" + Enum.GetName(typeof(M3HAxisType), m_axis) + m_speed + mark + stepStr;
  60. }
  61. }
  62. }
  63. #else
  64. using System;
  65. using System.Collections.Generic;
  66. using System.Linq;
  67. using System.Text;
  68. using System.Threading.Tasks;
  69. namespace StageController
  70. {
  71. /// <summary>
  72. /// 4.1 电脑控制电机按步运行指令
  73. /// </summary>
  74. public class CommandMoveByStep : CommandBase
  75. {
  76. private Axis m_axis;
  77. private int m_steps;
  78. private string m_speed;
  79. public CommandMoveByStep(Axis axis, int steps)
  80. {
  81. m_axis = axis;
  82. m_steps = steps;
  83. m_speed = "000";
  84. }
  85. public CommandMoveByStep(Axis axis, double steppingAccuracyMicron, double distanceMicron)
  86. {
  87. m_axis = axis;
  88. m_steps = (int)(distanceMicron / steppingAccuracyMicron);
  89. m_speed = "000";
  90. }
  91. public int Steps
  92. {
  93. get
  94. {
  95. return m_steps;
  96. }
  97. }
  98. public Axis Axis
  99. {
  100. get
  101. {
  102. return m_axis;
  103. }
  104. }
  105. public int Speed
  106. {
  107. set
  108. {
  109. if(value.ToString().Length > 3)
  110. {
  111. m_speed = "999";
  112. return;
  113. }
  114. m_speed = "000".Substring(0, 3 - value.ToString().Length) + value;
  115. }
  116. }
  117. public override string Make()
  118. {
  119. return buildCmd() +"WW!";
  120. }
  121. public override bool Parse(string response)
  122. {
  123. string tmpRes = "@" + Enum.GetName(typeof(Axis), m_axis) + m_speed ;
  124. if (response.Length==15 && response.StartsWith(tmpRes))
  125. {
  126. return true;
  127. }
  128. return false;
  129. }
  130. private string buildCmd()
  131. {
  132. string mark = "+";
  133. int tmpStep = m_steps;
  134. if (m_steps < 0)
  135. {
  136. mark = "-";
  137. tmpStep = -m_steps;
  138. }
  139. string stepStr = tmpStep.ToString();
  140. return "@" + Enum.GetName(typeof(Axis), m_axis) + m_speed + mark + "00000000".Substring(0, 8 - stepStr.Length) + stepStr;
  141. }
  142. }
  143. }
  144. #endif