You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Rs.DeweyTester/Rs.DeweyTester/Flow/SubFlow/FixtureTakeFlow.cs

250 lines
12 KiB
C#

using Rs.Controls;
using Rs.Framework;
using Rs.MotionPlat.Commom;
using Rs.MotionPlat.Entitys;
using Rs.MotionPlat.Flow.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Rs.MotionPlat.Flow.SubFlow
{
enum EFixtureTakeFlowStep
{
,
,
,
1,
1,
2,
2,
,
,
1,
1,
2,
2,
,
}
public class FixtureTakeFlow
{
bool finished = true;
EFixtureTakeFlowStep flowStep = EFixtureTakeFlowStep.;
public FixtureTakeFlow()
{
}
private static FixtureTakeFlow instance;
public static FixtureTakeFlow Instance
{
get
{
if (instance == null)
instance = new FixtureTakeFlow();
return instance;
}
}
public string GetCurStep()
{
return flowStep.ToString();
}
AlarmEntity alarmEntity = new AlarmEntity();
public void Take(int fixtureIndex,int nozzleIndex=-1,bool btest=false)
{
if (finished)
finished = false;
else
return;
flowStep = EFixtureTakeFlowStep.;
string logInfo = string.Empty;
TargetPosition targetPosition = new TargetPosition();
TestFixture curFixture = TestFixtureManager.Instance.GetTestFixture(fixtureIndex);
Nozzle curNozzle = null;
while (!finished)
{
if (MachineManage.Instance.MachineStatus == EMachineStatus.Stop)
{
Thread.Sleep(10);
continue;
}
switch (flowStep)
{
case EFixtureTakeFlowStep.:
flowStep = EFixtureTakeFlowStep.;
break;
case EFixtureTakeFlowStep.:
//先找出要放的吸嘴
if(nozzleIndex==-1)
{
curNozzle = NozzleManager.GetIdelNozzle();
}
else
{
curNozzle = NozzleManager.GetNozzle(nozzleIndex);
}
if (curNozzle != null)
{
targetPosition = NozzleManager.GetNozzleToFixturePos(curFixture.Index, curNozzle.NozzleIndex);
targetPosition.X += curFixture.PlaceProductOffsetX;
targetPosition.Y2 += curFixture.PlaceProductOffsetY;
if (GroupAxisMove.XY1Y2MovePos(targetPosition, GlobalVar.WholeSpeed))
{
AxisPosPrint.PrintXY1Y2TargetPos($"到治具{curFixture.Index}取料位上方", targetPosition, GetClassName());
flowStep = EFixtureTakeFlowStep.;
}
}
break;
case EFixtureTakeFlowStep.:
if (Ops.IsStop("LoadX", "LoadY1", "LoadY2"))
{
AxisPosPrint.PrintXY1Y2CurrentPos("轴loadx,loady1,loady2已停止运动,",GetClassName());
if (AxisArrived.LoadXY1Y2IsArrived(targetPosition.X, targetPosition.Y1, targetPosition.Y2))
{
AxisPosPrint.PrintXY1Y2CurrentPos($"已运动到治具{curFixture.Index}取料位上方,", GetClassName());
flowStep = EFixtureTakeFlowStep.1;
}
else
{
flowStep = EFixtureTakeFlowStep.;
}
}
break;
case EFixtureTakeFlowStep.1:
targetPosition.NozzleZ = NozzleManager.GetFixtureTakeProductPos(curFixture.Index, curNozzle.NozzleIndex);
if (NozzleManager.Go(curNozzle, targetPosition.NozzleZ, GlobalVar.WholeSpeed))
{
logInfo = GetClassName() + $"到治具{curFixture.Index}取料位下方1";
MessageQueue.Instance.Insert(logInfo);
flowStep = EFixtureTakeFlowStep.1;
}
break;
case EFixtureTakeFlowStep.1:
if (Ops.IsStop($"NozzleZ{curNozzle.NozzleIndex}"))
{
logInfo = GetClassName() + $"已运动到治具{curFixture.Index}取料位下方1";
MessageQueue.Instance.Insert(logInfo);
flowStep = EFixtureTakeFlowStep.2;
}
break;
case EFixtureTakeFlowStep.2:
targetPosition.NozzleZ = NozzleManager.GetFixtureTakeProductPos(curFixture.Index, curNozzle.NozzleIndex);
if (NozzleManager.Go(curNozzle, targetPosition.NozzleZ, GlobalVar.WholeSpeed))
{
logInfo = GetClassName() + $"到治具{curFixture.Index}取料位下方2";
MessageQueue.Instance.Insert(logInfo);
flowStep = EFixtureTakeFlowStep.2;
}
break;
case EFixtureTakeFlowStep.2:
if (Ops.IsStop($"NozzleZ{curNozzle.NozzleIndex}"))
{
Thread.Sleep(100);
logInfo = GetClassName() + $"已运动到治具{curFixture.Index}取料位下方2";
MessageQueue.Instance.Insert(logInfo);
if (GlobalVar.RunSpace)
{
flowStep = EFixtureTakeFlowStep.1;
}
else
{
//打开真空吸
curNozzle.VacSuction(EIoOperate.Open, GetClassName());
//松开夹头
curFixture.ColletOff(GetClassName());
flowStep = EFixtureTakeFlowStep.1;
}
}
break;
case EFixtureTakeFlowStep.1:
if (NozzleManager.GotoSafePos(curNozzle.NozzleIndex))
{
logInfo = GetClassName() + $"治具{curFixture.Index}取料完成抬起1";
MessageQueue.Instance.Insert(logInfo);
flowStep = EFixtureTakeFlowStep.1;
}
break;
case EFixtureTakeFlowStep.1:
if (Ops.IsStop($"NozzleZ{curNozzle.NozzleIndex}"))
{
logInfo = GetClassName() + $"治具{curFixture.Index}取料完成已抬起1";
MessageQueue.Instance.Insert(logInfo);
flowStep = EFixtureTakeFlowStep.2;
}
break;
case EFixtureTakeFlowStep.2:
if (NozzleManager.GotoSafePos(curNozzle.NozzleIndex))
{
logInfo = GetClassName() + $"治具{curFixture.Index}取料完成抬起2";
MessageQueue.Instance.Insert(logInfo);
flowStep = EFixtureTakeFlowStep.2;
}
else
{
Msg.ShowError($"轴NozzleZ{curNozzle.NozzleIndex}运动异常");
}
break;
case EFixtureTakeFlowStep.2:
if (Ops.IsStop($"NozzleZ{curNozzle.NozzleIndex}"))
{
logInfo = GetClassName() + $"治具{curFixture.Index}取料完成已抬起2";
MessageQueue.Instance.Insert(logInfo);
flowStep = EFixtureTakeFlowStep.;
}
break;
case EFixtureTakeFlowStep.:
if (curNozzle.HasProduct() || GlobalVar.RunSpace)
{
if(btest)
{
finished = true;
flowStep = EFixtureTakeFlowStep.;
}
else
{
logInfo = $"{GetClassName()}治具{curFixture.Index}中产品SN:{curFixture.Product.SN}被吸嘴{curNozzle.NozzleIndex}取出";
MessageQueue.Instance.Insert(logInfo);
curNozzle.Product = curFixture.Product;
if (curFixture.Product.Result == "PASS" || curFixture.Product.TestNum == 3)
{
curNozzle.Status = ENozzleStatus.ToUnload;
}
else
{
curNozzle.Status = ENozzleStatus.ToTest;
}
curFixture.Clear();
GlobalTray.NozzleTray.ChangeStatus(curNozzle.NozzleIndex, ESlotStatus.Have);
finished = true;
flowStep = EFixtureTakeFlowStep.;
}
}
else
{
alarmEntity = AlarmCollection.Get(AlarmConstID.).Transform(curNozzle.NozzleIndex, curFixture.Index);
Msgbox.ShowDialog(alarmEntity, EButtonType.Recheck, true);
//Msgbox.ShowTipDialog(EButtonType.Recheck, $"吸嘴{curNozzle.NozzleIndex}从治具{curFixture.Index}取料时真空检测异常,请处理","vac error",true);
}
break;
default:
break;
}
Thread.Sleep(5);
}
}
string GetClassName()
{
return $"{nameof(FixtureTakeFlow)}-";
}
}
}