using HalconDotNet;
using Rs.Controls;
using Rs.Framework;
using Rs.Motion;
using Rs.MotionPlat.Commom;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Rs.MotionPlat.Flow.SafePosFlow
{
///
/// 排料头模组回安全位
///
public class DischargeModuleGoSafePosFlow: GoSafePosFlow
{
private static DischargeModuleGoSafePosFlow instance;
public static DischargeModuleGoSafePosFlow Instance
{
get
{
if (instance == null)
instance = new DischargeModuleGoSafePosFlow();
return instance;
}
}
///
/// 排料头回安全位
///
public override void GoSafePostion(EExceptionSafePos ePos = EExceptionSafePos.Socket)
{
if (finished)
{
taskFinishedEvent.Reset();
finished = false;
}
else {
MessageQueue.Instance.Warn("检测到回安全位还未结束");
return;
}
step = EGoSafePosFlowStep.到安全位;
while (true && !finished)
{
if (MachineManage.Instance.MachineStatus == EMachineStatus.Stop)
{
Thread.Sleep(10);
continue;
}
switch (step)
{
case EGoSafePosFlowStep.到安全位:
errCode = AxisControl.LoadX.MovePos(SysConfigParam.GetValue("LoadXStartPos"), GlobalVar.WholeSpeed);
if (errCode == ErrorCode.Ok || GlobalVar.VirtualAxis)
{
errCode = AxisControl.LoadY.MovePos(SysConfigParam.GetValue("LoadYStartPos"), GlobalVar.WholeSpeed);
if (errCode == ErrorCode.Ok || GlobalVar.VirtualAxis)
{
logInfo = GetClassName() + $"到安全位";
MessageQueue.Instance.Insert(logInfo);
if (GlobalVar.VirtualAxis)
{
Thread.Sleep(GlobalVar.VirtualAxisMoveTime);
}
step = EGoSafePosFlowStep.等待运动到安全位;
}
else
{
PromptMessageBox.ShowAxisAlarmDialog(AxisControl.LoadX, errCode);
}
}
else
{
PromptMessageBox.ShowAxisAlarmDialog(AxisControl.LoadY, errCode);
}
break;
case EGoSafePosFlowStep.等待运动到安全位:
if (Ops.IsStop("LoadX", "LoadY") || GlobalVar.VirtualAxis)
{
logInfo = GetClassName() + $"已运动到安全位";
MessageQueue.Instance.Insert(logInfo);
finished = true;
taskFinishedEvent.Set();
}
break;
default:
break;
}
Thread.Sleep(10);
}
//taskFinishedEvent.WaitOne();
}
///
/// 判断是否在安全位
///
///
public bool IsInSafePostion()
{
double x = SysConfigParam.GetValue("LoadXStartPos");
double y = SysConfigParam.GetValue("LoadYStartPos");
if(Math.Abs(Ops.GetCurPosition(AxisControl.LoadX)-x)<0.1 && Math.Abs(Ops.GetCurPosition(AxisControl.LoadY) - y)<0.1)
{
return true;
}
return false;
}
public string GetClassName()
{
return "DischargeModuleGoSafePosFlow-";
}
public void Wait()
{
taskFinishedEvent.WaitOne();
}
}
}