using StageController.M3H;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
#if true
namespace StageController
{
///
/// 4.1 电脑控制电机按步运行指令
///
public class CommandMoveByStep : CommandBase
{
private M3HAxisType m_axis;
private int m_steps;
private string m_speed;
public CommandMoveByStep(M3HAxisType axis, int steps, int speed)
{
m_axis = axis;
m_steps = steps;
Speed = speed;
}
public int Speed
{
set
{
if (value.ToString().Length > 3)
{
m_speed = "999";
return;
}
m_speed = "000".Substring(0, 3 - value.ToString().Length) + value;
}
}
public override string Make()
{
return buildCmd() + "!";
}
public override bool Parse(string response)
{
string tmpRes = "@" + Enum.GetName(typeof(M3HAxisType), m_axis) + m_speed;
if (response.Length == 15 && response.StartsWith(tmpRes))
{
return true;
}
return false;
}
private string buildCmd()
{
string mark = "+";
int tmpStep = m_steps;
if (m_steps < 0)
{
mark = "-";
tmpStep = -m_steps;
}
string stepStr = tmpStep.ToString("D8");
return "@" + Enum.GetName(typeof(M3HAxisType), m_axis) + m_speed + mark + stepStr;
}
}
}
#else
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StageController
{
///
/// 4.1 电脑控制电机按步运行指令
///
public class CommandMoveByStep : CommandBase
{
private Axis m_axis;
private int m_steps;
private string m_speed;
public CommandMoveByStep(Axis axis, int steps)
{
m_axis = axis;
m_steps = steps;
m_speed = "000";
}
public CommandMoveByStep(Axis axis, double steppingAccuracyMicron, double distanceMicron)
{
m_axis = axis;
m_steps = (int)(distanceMicron / steppingAccuracyMicron);
m_speed = "000";
}
public int Steps
{
get
{
return m_steps;
}
}
public Axis Axis
{
get
{
return m_axis;
}
}
public int Speed
{
set
{
if(value.ToString().Length > 3)
{
m_speed = "999";
return;
}
m_speed = "000".Substring(0, 3 - value.ToString().Length) + value;
}
}
public override string Make()
{
return buildCmd() +"WW!";
}
public override bool Parse(string response)
{
string tmpRes = "@" + Enum.GetName(typeof(Axis), m_axis) + m_speed ;
if (response.Length==15 && response.StartsWith(tmpRes))
{
return true;
}
return false;
}
private string buildCmd()
{
string mark = "+";
int tmpStep = m_steps;
if (m_steps < 0)
{
mark = "-";
tmpStep = -m_steps;
}
string stepStr = tmpStep.ToString();
return "@" + Enum.GetName(typeof(Axis), m_axis) + m_speed + mark + "00000000".Substring(0, 8 - stepStr.Length) + stepStr;
}
}
}
#endif