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.

216 lines
9.2 KiB
C#

using Rs.Controls;
using Rs.Framework;
using Rs.MotionPlat.Commom;
using Rs.MotionPlat.Entitys;
using Rs.MotionPlat.Flow.Common;
using Rs.MotionPlat.Flow.SafePosFlow;
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 EStockPlaceFlowStep
{
,
,
,
,
,
,
,
}
/// <summary>
/// 料仓放料流程
/// </summary>
public class StockPlaceFlow
{
public event Action<TestProduct> PlaceFinishedEvent;
bool finished = true;
EStockPlaceFlowStep flowStep = EStockPlaceFlowStep.;
public StockPlaceFlow()
{
}
private static StockPlaceFlow instance;
public static StockPlaceFlow Instance
{
get
{
if (instance == null)
instance = new StockPlaceFlow();
return instance;
}
}
public string GetCurStep()
{
return flowStep.ToString();
}
/// <summary>
/// 料仓放料
/// </summary>
/// <param name="tray">需要放入的料盘</param>
/// <param name="nozzleIndex">哪个吸嘴放</param>
/// <param name="className"></param>
public void Place(ETrayType trayType,int slotIndex,int nozzleIndex)
{
RsTray tray = null;
if (finished)
finished = false;
else
return;
switch (trayType)
{
case ETrayType.Ng:
tray = GlobalTray.NgTray;
break;
case ETrayType.ReTest:
tray = GlobalTray.RetestTray;
break;
case ETrayType.Grr:
tray = GlobalTray.GrrTray;
break;
case ETrayType.Ok:
tray = GlobalTray.OkTary;
break;
case ETrayType.Input:
tray = GlobalTray.InputTray;
break;
default:
break;
}
flowStep = EStockPlaceFlowStep.;
string logInfo = string.Empty;
TargetPosition targetPosition = new TargetPosition();
Nozzle curNozzle = NozzleManager.GetNozzle(nozzleIndex);
TraySlot curPlaceSlot = null;
while (!finished)
{
if (MachineManage.Instance.MachineStatus == EMachineStatus.Stop)
{
Thread.Sleep(10);
continue;
}
switch (flowStep)
{
case EStockPlaceFlowStep.:
flowStep = EStockPlaceFlowStep.;
break;
case EStockPlaceFlowStep.:
//curNozzle = NozzleManager.GetToUnloadNozzle();
curNozzle = NozzleManager.GetNozzle(nozzleIndex);
if (curNozzle != null)
{
curPlaceSlot = tray.GetSlot(slotIndex);
if (curPlaceSlot != null)
{
targetPosition = NozzleManager.GetToTraySlot(trayType, curPlaceSlot.Index, curNozzle.NozzleIndex);
if (GroupAxisMove.XY1Y2MovePos(targetPosition, GlobalVar.WholeSpeed))
{
AxisPosPrint.PrintXY1Y2TargetPos("到料仓放料位上方,", targetPosition, GetClassName());
flowStep = EStockPlaceFlowStep.;
}
}
else
{
}
}
break;
case EStockPlaceFlowStep.:
if (Ops.IsStop("LoadX", "LoadY1", "LoadY2"))
{
AxisPosPrint.PrintXY1Y2CurrentPos("轴loadx,loady1,loady2已停止运动,",GetClassName());
if (AxisArrived.LoadXY1Y2IsArrived(targetPosition.X, targetPosition.Y1, targetPosition.Y2))
{
AxisPosPrint.PrintXY1Y2CurrentPos("已运动到料仓放料位上方,", GetClassName());
flowStep = EStockPlaceFlowStep.;
}
else
{
flowStep = EStockPlaceFlowStep.;
}
}
break;
case EStockPlaceFlowStep.:
targetPosition.StockZ = NozzleManager.GetNozzleToTrayTakeProductPos(trayType, curNozzle.NozzleIndex);
if (NozzleManager.Go(curNozzle, targetPosition.StockZ, GlobalVar.WholeSpeed))
{
logInfo = $"{GetClassName()}到料仓放料位下方";
MessageQueue.Instance.Insert(logInfo);
flowStep = EStockPlaceFlowStep.;
}
break;
case EStockPlaceFlowStep.:
if (Ops.IsStop($"NozzleZ{curNozzle.NozzleIndex}"))
{
logInfo = $"{GetClassName()}已运动到料仓放料位下方";
MessageQueue.Instance.Insert(logInfo);
//关闭真空吸
curNozzle.VacSuction(EIoOperate.Close, GetClassName());
//打开真空破
curNozzle.VacBreak(EIoOperate.Open, GetClassName());
//关闭真空
curNozzle.VacBreak(EIoOperate.Close, GetClassName());
flowStep = EStockPlaceFlowStep.;
}
break;
case EStockPlaceFlowStep.:
if (NozzleManager.GotoSafePos(curNozzle.NozzleIndex))
{
logInfo = $"{GetClassName()}料仓放料完成抬起";
MessageQueue.Instance.Insert(logInfo);
flowStep = EStockPlaceFlowStep.;
}
break;
case EStockPlaceFlowStep.:
if (Ops.IsStop($"NozzleZ{curNozzle.NozzleIndex}"))
{
logInfo = $"{GetClassName()}放料完成已抬起";
MessageQueue.Instance.Insert(logInfo);
flowStep = EStockPlaceFlowStep.;
}
break;
case EStockPlaceFlowStep.:
if (!curNozzle.HasProduct() || GlobalVar.RunSpace)
{
PlaceFinishedEvent?.Invoke(curNozzle.Product);
logInfo = $"{GetClassName()}检测到吸嘴{curNozzle.NozzleIndex}无粘料,吸嘴{curNozzle.NozzleIndex}把产品SN:{curNozzle.Product.SN}放入OK料盘{curPlaceSlot.Index}穴位";
MessageQueue.Instance.Insert(logInfo);
tray.ChangeStatus(curPlaceSlot.Index, ESlotStatus.Have);
curNozzle.Product.ToString();
curNozzle.Clear();
finished = true;
flowStep = EStockPlaceFlowStep.;
}
else
{
AlarmEntity alarmEntity = AlarmCollection.Get(AlarmConstID.).Transform(curNozzle.NozzleIndex);
if(alarmEntity != null)
{
Msgbox.ShowDialog(alarmEntity, EButtonType.Retry);
}
else
{
Msg.ShowError("翻译文件中未找到 ‘排料吸嘴粘料报警’项");
}
}
break;
}
}
}
string GetClassName()
{
return $"{nameof(StockPlaceFlow)}-";
}
}
}