/// <summary>
/// 控制卡类
/// </summary>
public class Card : EntityBase<short>
{
public Card(short key, CardPrm prm, ICardExecuter executer) : base(key)
{
Prm = prm;
Executer = executer;
}
public Result GetLibVer(out string libVer, out string motionVer, out string firmWareVer)
{
libVer = string.Empty;
motionVer = string.Empty;
firmWareVer = string.Empty;
int verNum, motionNum, firmNum;
var rtn = Executer.GetLibVer(Key, out verNum, out motionNum, out firmNum);
libVer = verNum.ToString();
motionVer = motionNum.ToString();
firmWareVer = firmNum.ToString();
return rtn;
}
/// <summary>
/// 参数
/// </summary>
public CardPrm Prm { get; set; }
/// <summary>
/// 控制卡要用到的接口
/// </summary>
public ICardExecuter Executer { get; private set; }
/// <summary>
/// 初始化控制卡
/// </summary>
public Result Open()
{
try
{
var rtn = Executer.Open(Key);
Thread.Sleep(300);
if (!rtn.IsOk)
{
return rtn;
}
rtn = Executer.LoadConfig(Key);
return rtn;
}
catch (Exception ex)
{
return new Result(false, ex);
}
}
/// <summary>
/// 停止轴
/// </summary>
/// <param name="axis">轴号</param>
/// <param name="isAbout">是否急停,true == 急停</param>
/// <returns></returns>
public Result StopAxis(short axis, bool isAbout)
{
if (isAbout)
{
return Executer.Stop(axis, 1, Key);
}
else
{
return Executer.Stop(axis, 0, Key);
}
}
/// <summary>
/// 停止轴
/// </summary>
public Result StopGoHome(short axis)
{
return Executer.StopGoHome(axis, Key);
}
/// <summary>
/// 等待插补运动结束
/// </summary>
public Result WaitCrdEnd(short crd)
{
bool isRun = true;
Result rtn = Result.OK;
while (isRun)
{
rtn = Executer.GetCrdState(crd, out isRun, Key);
if (!rtn.IsOk)
{
return rtn;
}
Thread.Sleep(10);
}
return rtn;
}
/// <summary>
/// 插补是否在进行
/// </summary>
public bool CrdInRun(short crd)
{
bool isRun = false;
var rtn = Executer.GetCrdState(crd, out isRun, Key);
if (!rtn.IsOk)
{
return false;
}
return isRun;
}
/// <summary>
/// 回原点,不阻塞
/// </summary>
public Result GoHome(short axis, AxisHomeType mode, double vel, double acc, int offset, double lvel)
{
return Executer.GoHome(axis, mode, vel, acc, offset, lvel, Key);
}
/// <summary>
/// 清零
/// </summary>
public Result Zero(short axis)
{
return Executer.ZeroPos(axis, Key);
}
public void Close()
{
Executer.Close(Key);
}
}