优化8头

Eight
lhiven 4 weeks ago
parent e9073cb450
commit fd0f5d1b33

@ -0,0 +1,24 @@
using Rs.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Rs.MotionPlat.Commom
{
public static class BarCodeHelper
{
public static bool CheckSnLength(string sn)
{
//string reg = "^[ABCDEFGHJKLMNPQRSTUVWXYZ 0-9 + -]+$";
string reg = "^[A-Z 0-9 + -]+$";
if (Regex.IsMatch(sn, reg))
{
return true;
}
return false;
}
}
}

@ -34,6 +34,26 @@ namespace Rs.MotionPlat.Commom
return ret;
}
public static EButtonType ShowTipDialog(AlarmEntity alarmInfo, EButtonType buttons, bool warning = false)
{
if (warning)
{
BuzzerManager.Instance.On();
LightManger.Instance.SetStatus(ELightStatus.Red);
}
string logInfo = $"{alarmInfo.CN}";
LogHelper.Debug($"ShowTipDialog({logInfo},{buttons}, {warning})");
EButtonType ret = EButtonType.None;
FrmDialog fd = new FrmDialog();
ret = fd.ShowMessage(buttons, alarmInfo.CN, alarmInfo.EN);
if (warning)
{
BuzzerManager.Instance.Off();
LightManger.Instance.SetStatus(ELightStatus.Green);
}
return ret;
}
/// <summary>
/// 显示模态弹框
/// </summary>

@ -0,0 +1,41 @@
using Rs.Framework;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Rs.MotionPlat.Commom
{
public class ScanFailNGHelper
{
static int sn;
static string filename = "ng-sn.txt";
static ScanFailNGHelper()
{
if(File.Exists(filename))
{
string fc = File.ReadAllText(filename);
if(!int.TryParse(fc, out sn ))
{
sn = 0;
}
}
}
public static string GetSn()
{
sn++;
File.WriteAllText(filename, sn.ToString());
return $"SLK{GlobalVar.MachineID}"+ sn.ToString().PadLeft(9, '0');
}
public static bool IsScanFailSN(string sn)
{
string reg = "SLKADT\\d{11}";
return Regex.IsMatch(sn, reg);
}
}
}

@ -1,6 +1,8 @@
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using Rs.Framework;
using Rs.MotionPlat.Commom;
using Rs.MotionPlat.Flow;
using System;
using System.Collections.Generic;
using System.IO;
@ -128,6 +130,20 @@ namespace Rs.MotionPlat.Entitys
}
return "";
}
public static void SystemExceptionAlarm(Exception ex)
{
LogHelper.Debug(ex.Message + ex.StackTrace);
AlarmEntity alarmEntity = AlarmCollection.Get(AlarmConstID.).Transform(ex.Message);
if (alarmEntity != null)
{
Msgbox.ShowTipDialog(alarmEntity, EButtonType.Ok, true);
}
else
{
Msg.ShowError("Alarm file cann't find 系统异常报警 item");
}
}
}
public class AlarmEntity
{

@ -244,5 +244,48 @@ namespace Rs.MotionPlat.Flow
/// 二维码长度异常报警
/// </summary>
public const int = 1049;
/// <summary>
/// Input料盘开始搬运到Empty前报警
/// </summary>
public const int InputEmpty = 1050;
/// <summary>
/// 轴未到位异常
/// </summary>
public const int = 1051;
/// <summary>
/// 命令发送失败报警
/// </summary>
public const int = 1052;
/// <summary>
/// 等待命令超时报警
/// </summary>
public const int = 1053;
/// <summary>
/// 设备长时间未动作报警
/// </summary>
public const int = 1054;
/// <summary>
/// 有无相机拍照失败报警
/// </summary>
public const int = 1055;
/// <summary>
/// 系统异常报警
/// </summary>
public const int = 1056;
/// <summary>
/// 测试软件异常报警
/// </summary>
public const int = 1057;
}
}

@ -1,4 +1,5 @@
using NPOI.SS.Formula.Eval;
using Newtonsoft.Json;
using NPOI.SS.Formula.Eval;
using Rs.Camera;
using Rs.Controls;
using Rs.Framework;
@ -366,135 +367,200 @@ namespace Rs.MotionPlat.Flow
}
break;
case EDischargeFlowStep.:
ProductLocationResult ret = productLocationResult.Where(r => r.SlotIndex == takeSlotIndex).FirstOrDefault();
if(ret != null || GlobalVar.RunSpace)
try
{
if((ret!= null && ret.Result== EOneGrabSixteenResult.Ok) ||(ret!=null &&ret.Result== EOneGrabSixteenResult.LocationOkScanBarcodeFail && GlobalVar.EnableVirtualBarCode) || GlobalVar.RunSpace)
ProductLocationResult ret = productLocationResult.Where(r => r.SlotIndex == takeSlotIndex).FirstOrDefault();
if (ret != null || GlobalVar.RunSpace)
{
Nozzle idleNozzle = NozzleManager.GetIdelNozzle();
if(idleNozzle!=null)
if ((ret != null && ret.Result == EOneGrabSixteenResult.Ok) || (ret != null && ret.Result == EOneGrabSixteenResult.LocationOkScanBarcodeFail && GlobalVar.EnableVirtualBarCode) || GlobalVar.RunSpace)
{
StockTakeFlow.Instance.Take(ETrayType.Input, takeSlotIndex, idleNozzle.NozzleIndex);
takeSlotIndex++;
flowStep = EDischargeFlowStep.;
}
}
else
{
bool exit = false;
while (!exit)
{
ProductLocationResult fixtureret = FixedGrabProductFlow.Instance.TakePicture(ETrayType.Input, ret.SlotIndex);
if (fixtureret.Result == EOneGrabSixteenResult.Ok)
if (GlobalVar.RunSpace || BarCodeHelper.CheckSnLength(ret.SN) || (ret != null && ret.Result == EOneGrabSixteenResult.LocationOkScanBarcodeFail && GlobalVar.EnableVirtualBarCode))
{
if(fixtureret.SN.Length==GlobalVar.BarcodeLength)
{
ret.Change(fixtureret.SN, fixtureret.OffsetX, fixtureret.OffsetY);
//takeSlotIndex++;
StockTakeFlow.Instance.Take(ETrayType.Input, takeSlotIndex, NozzleManager.GetIdelNozzle().NozzleIndex);
takeSlotIndex++;
flowStep = EDischargeFlowStep.;
exit = true;
}
else
{
//报警弹框
alarmEntity = AlarmCollection.Get(AlarmConstID.).Transform(ret.SlotIndex);
EButtonType buttonSelect = Msgbox.ShowDialog(alarmEntity, EButtonType.Retry, true);
if (buttonSelect == EButtonType.Retry)
{
logInfo = GetClassName() + "选择了重试";
MessageQueue.Instance.Insert(logInfo);
}
}
StockTakeFlow.Instance.Take(ETrayType.Input, takeSlotIndex, NozzleManager.GetIdelNozzle().NozzleIndex);
takeSlotIndex++;
flowStep = EDischargeFlowStep.;
}
else if (fixtureret.Result == EOneGrabSixteenResult.LocationOkScanBarcodeFail)
else
{
LogHelper.Debug(GetClassName() + $"检测到二维码={ret.SN}长度和设置的长度={GlobalVar.BarcodeLength}不一致");
Nozzle idleNozzle = NozzleManager.GetIdelNozzle();
if(false)
StockTakeFlow.Instance.Take(ETrayType.Input, ret.SlotIndex, idleNozzle.NozzleIndex);
if (NozzleManager.GetNozzle(idleNozzle.NozzleIndex).Product != null)
{
StockTakeFlow.Instance.Take(ETrayType.Input, ret.SlotIndex, idleNozzle.NozzleIndex);
//放料
TraySlot noProductSlot = GlobalTray.RetestTray.GetSlot(ESlotStatus.NotHave);
if (noProductSlot != null)
{
StockPlaceFlow.Instance.Place(ETrayType.ReTest, noProductSlot.Index, idleNozzle.NozzleIndex);
}
else
{
Msgbox.ShowTipDialog(EButtonType.Ok, "Retest tray full,please change tray and click ok button", "tip", true);
GlobalTray.RetestTray.ChangeStatus(ESlotStatus.NotHave);
ThreePointLocationFlow.Instance.Location(ETrayType.ReTest);
//放料
noProductSlot = GlobalTray.RetestTray.GetSlot(ESlotStatus.NotHave);
StockPlaceFlow.Instance.Place(ETrayType.ReTest, noProductSlot.Index, idleNozzle.NozzleIndex);
}
takeSlotIndex++;
flowStep = EDischargeFlowStep.;
exit = true;
//NozzleManager.GetNozzle(idleNozzle.NozzleIndex).Product.SN = "SLK11111111PNK60X";
NozzleManager.GetNozzle(idleNozzle.NozzleIndex).Product.SN = ScanFailNGHelper.GetSn();
}
else
{
StockTakeFlow.Instance.Take(ETrayType.Input, ret.SlotIndex, idleNozzle.NozzleIndex);
if(NozzleManager.GetNozzle(idleNozzle.NozzleIndex).Product!=null)
{
NozzleManager.GetNozzle(idleNozzle.NozzleIndex).Product.SN = "SLK11111111PNK60X";
}
takeSlotIndex++;
exit = true;
flowStep = EDischargeFlowStep.;
}
takeSlotIndex++;
flowStep = EDischargeFlowStep.;
}
else if (fixtureret.Result == EOneGrabSixteenResult.Slant)
}
else
{
bool exit = false;
while (!exit)
{
//报警弹框
alarmEntity = AlarmCollection.Get(AlarmConstID.).Transform(ret.SlotIndex);
EButtonType buttonSelect = Msgbox.ShowDialog(alarmEntity, EButtonType.Skip | EButtonType.Retry | EButtonType.EndInput, true);
//EButtonType buttonSelect = Msgbox.ShowDialog(EButtonType.Skip | EButtonType.Retry | EButtonType.EndInput, $"穴位{ret.SlotIndex}定位失败,请把产品手动取走后点击跳过","tip",true);
if(buttonSelect== EButtonType.Retry)
//先进行有无料判断
ProductLocationResult fixtureret = FixedGrabProductFlow.Instance.TakePicture(ETrayType.Input, ret.SlotIndex, 1, true);
if (fixtureret.Result == EOneGrabSixteenResult.NoHaveProdut)
{
logInfo = GetClassName() + "选择了重试";
MessageQueue.Instance.Insert(logInfo);
}
else if (buttonSelect == EButtonType.Skip)
{
logInfo = GetClassName() + "选择了跳过";
MessageQueue.Instance.Insert(logInfo);
logInfo = GetClassName() + $"视觉检测到穴位{ret.SlotIndex}无料,自动跳过";
LogHelper.Debug(logInfo);
exit = true;
GlobalTray.InputTray.ChangeStatus(ret.SlotIndex, ESlotStatus.NotHave);
takeSlotIndex++;
flowStep = EDischargeFlowStep.;
}
else if (buttonSelect == EButtonType.EndInput)
else if (fixtureret.Result == EOneGrabSixteenResult.Slant)
{
logInfo = GetClassName() + "选择了结束上料";
MessageQueue.Instance.Insert(logInfo);
exit = true;
GlobalVar.Clear = true;
takeSlotIndex++;
flowStep = EDischargeFlowStep.;
logInfo = GetClassName() + $"视觉检测到穴位{ret.SlotIndex}有料";
LogHelper.Debug(logInfo);
fixtureret = FixedGrabProductFlow.Instance.TakePicture(ETrayType.Input, ret.SlotIndex);
if (fixtureret != null && fixtureret.Result == EOneGrabSixteenResult.Ok)
{
LogHelper.Debug(GetClassName() + $"{JsonConvert.SerializeObject(fixtureret)}");
//if (fixtureret.SN.Length == GlobalVar.BarcodeLength)
if (BarCodeHelper.CheckSnLength(fixtureret.SN))
{
try
{
LogHelper.Debug(GetClassName() + "检测到二维码长度和设置的长度一致");
ret.Change(fixtureret.SN, fixtureret.OffsetX, fixtureret.OffsetY);
//takeSlotIndex++;
LogHelper.Debug(GetClassName() + $"产品二维码:{fixtureret.SN}准备取料");
StockTakeFlow.Instance.Take(ETrayType.Input, takeSlotIndex, NozzleManager.GetIdelNozzle().NozzleIndex);
takeSlotIndex++;
flowStep = EDischargeFlowStep.;
exit = true;
}
catch (Exception ex)
{
Msg.ShowError(ex.Message);
}
}
else
{
try
{
LogHelper.Debug(GetClassName() + $"检测到二维码={fixtureret.SN}长度和设置的长度={GlobalVar.BarcodeLength}不一致");
Nozzle idleNozzle = NozzleManager.GetIdelNozzle();
StockTakeFlow.Instance.Take(ETrayType.Input, ret.SlotIndex, idleNozzle.NozzleIndex);
if (NozzleManager.GetNozzle(idleNozzle.NozzleIndex).Product != null)
{
//NozzleManager.GetNozzle(idleNozzle.NozzleIndex).Product.SN = "SLK11111111PNK60X";
NozzleManager.GetNozzle(idleNozzle.NozzleIndex).Product.SN = ScanFailNGHelper.GetSn();
}
takeSlotIndex++;
exit = true;
flowStep = EDischargeFlowStep.;
////报警弹框
//alarmEntity = AlarmCollection.Get(AlarmConstID.二维码长度异常报警).Transform(ret.SlotIndex);
//EButtonType buttonSelect = Msgbox.ShowDialog(alarmEntity, EButtonType.Retry, true);
//if (buttonSelect == EButtonType.Retry)
//{
// logInfo = GetClassName() + "选择了重试";
// MessageQueue.Instance.Insert(logInfo);
//}
}
catch (Exception ex)
{
Msg.ShowError(ex.Message);
}
}
}
else if (fixtureret != null && fixtureret.Result == EOneGrabSixteenResult.LocationOkScanBarcodeFail)
{
Nozzle idleNozzle = NozzleManager.GetIdelNozzle();
//if (!GlobalVar.ScanFailToTest)
if (false)
{
StockTakeFlow.Instance.Take(ETrayType.Input, ret.SlotIndex, idleNozzle.NozzleIndex);
//放料
TraySlot noProductSlot = GlobalTray.RetestTray.GetSlot(ESlotStatus.NotHave);
if (noProductSlot != null)
{
StockPlaceFlow.Instance.Place(ETrayType.ReTest, noProductSlot.Index, idleNozzle.NozzleIndex);
}
else
{
Msgbox.ShowTipDialog(EButtonType.Ok, "Retest tray full,please change tray and click ok button", "tip", true);
GlobalTray.RetestTray.ChangeStatus(ESlotStatus.NotHave);
ThreePointLocationFlow.Instance.Location(ETrayType.ReTest);
//放料
noProductSlot = GlobalTray.RetestTray.GetSlot(ESlotStatus.NotHave);
StockPlaceFlow.Instance.Place(ETrayType.ReTest, noProductSlot.Index, idleNozzle.NozzleIndex);
}
takeSlotIndex++;
flowStep = EDischargeFlowStep.;
exit = true;
}
else
{
StockTakeFlow.Instance.Take(ETrayType.Input, ret.SlotIndex, idleNozzle.NozzleIndex);
if (NozzleManager.GetNozzle(idleNozzle.NozzleIndex).Product != null)
{
//NozzleManager.GetNozzle(idleNozzle.NozzleIndex).Product.SN = "SLK11111111PNK60X";
NozzleManager.GetNozzle(idleNozzle.NozzleIndex).Product.SN = ScanFailNGHelper.GetSn();
}
takeSlotIndex++;
exit = true;
flowStep = EDischargeFlowStep.;
}
}
else if (fixtureret != null && fixtureret.Result == EOneGrabSixteenResult.Slant)
{
//if (GlobalVar.BinTakeGrabFailSkip)
if(true)
{
logInfo = GetClassName() + "系统设置了取料拍照失败自动跳过";
MessageQueue.Instance.Insert(logInfo);
exit = true;
//GlobalTray.InputTray.ChangeStatus(ret.SlotIndex, ESlotStatus.NotHave);
takeSlotIndex++;
flowStep = EDischargeFlowStep.;
}
else
{
//报警弹框
alarmEntity = AlarmCollection.Get(AlarmConstID.).Transform(ret.SlotIndex);
EButtonType buttonSelect = Msgbox.ShowDialog(alarmEntity, EButtonType.Skip | EButtonType.Retry | EButtonType.EndInput, true);
//EButtonType buttonSelect = Msgbox.ShowDialog(EButtonType.Skip | EButtonType.Retry | EButtonType.EndInput, $"穴位{ret.SlotIndex}定位失败,请把产品手动取走后点击跳过","tip",true);
if (buttonSelect == EButtonType.Retry)
{
logInfo = GetClassName() + "选择了重试";
MessageQueue.Instance.Insert(logInfo);
}
else if (buttonSelect == EButtonType.Skip)
{
logInfo = GetClassName() + "选择了跳过";
MessageQueue.Instance.Insert(logInfo);
exit = true;
GlobalTray.InputTray.ChangeStatus(ret.SlotIndex, ESlotStatus.NotHave);
takeSlotIndex++;
flowStep = EDischargeFlowStep.;
}
else if (buttonSelect == EButtonType.EndInput)
{
logInfo = GetClassName() + "选择了结束上料";
MessageQueue.Instance.Insert(logInfo);
exit = true;
GlobalVar.Clear = true;
takeSlotIndex++;
flowStep = EDischargeFlowStep.;
}
}
}
}
}
else if(fixtureret.Result== EOneGrabSixteenResult.NoHaveProdut)
{
logInfo =GetClassName()+ $"视觉检测到穴位{ret.SlotIndex}无料,自动跳过";
exit = true;
GlobalTray.InputTray.ChangeStatus(ret.SlotIndex, ESlotStatus.NotHave);
takeSlotIndex++;
flowStep = EDischargeFlowStep.;
}
}
}
}
//if (GlobalTray.InputTray.GetSlot(takeSlotIndex).SlotStatus == ESlotStatus.Have)
//{
// StockTakeFlow.Instance.Take(takeSlotIndex, NozzleManager.GetIdelNozzle().NozzleIndex);
//}
//takeSlotIndex++;
//flowStep = EDischargeFlowStep.判断是否需要从料仓取料;
catch (Exception ex)
{
AlarmCollection.SystemExceptionAlarm(ex);
}
break;
#endregion

@ -268,56 +268,63 @@ namespace Rs.MotionPlat.Flow
}
break;
case EGrrFlowStep.:
if(VisionHelper.oneGrabOneVision.ClearQueue())
try
{
UpCameraHelper.Grab();
string msg = VisionHelper.OneGrabOne();//.Grab(EVisionScene.SingleScanBarcode);
if(!string.IsNullOrEmpty(msg))
if (VisionHelper.oneGrabOneVision.ClearQueue("C"))
{
vProductResult.Parse(msg);
if ((vProductResult != null && vProductResult.Result == EOneGrabSixteenResult.Ok) || GlobalVar.RunSpace)
UpCameraHelper.Grab();
string msg = VisionHelper.OneGrabOne("M");
if (!string.IsNullOrEmpty(msg))
{
if(vProductResult.SN.Length==GlobalVar.BarcodeLength)
vProductResult.Parse(msg);
if ((vProductResult != null && vProductResult.Result == EOneGrabSixteenResult.Ok) || GlobalVar.RunSpace)
{
flowStep = EGrrFlowStep.;
}
else
{
alarmEntity = AlarmCollection.Get(AlarmConstID.);
Msgbox.ShowDialog(alarmEntity, EButtonType.Retry);
}
}
else if (vProductResult != null && vProductResult.Result == EOneGrabSixteenResult.LocationOkScanBarcodeFail)
{
GrrScanFailFrm scanFail = new GrrScanFailFrm((act, qrcode) => {
if (act == 1)
//if(vProductResult.SN.Length==GlobalVar.BarcodeLength)
if (BarCodeHelper.CheckSnLength(vProductResult.SN) || GlobalVar.RunSpace)
{
vProductResult.SN = qrcode;
flowStep = EGrrFlowStep.;
}
});
scanFail.ShowDialog();
//vProductResult.SN = VirtualBarCode.Code;
else
{
alarmEntity = AlarmCollection.Get(AlarmConstID.);
Msgbox.ShowDialog(alarmEntity, EButtonType.Retry, true);
}
}
else if (vProductResult != null && vProductResult.Result == EOneGrabSixteenResult.LocationOkScanBarcodeFail)
{
GrrScanFailFrm scanFail = new GrrScanFailFrm((act, qrcode) => {
if (act == 1)
{
vProductResult.SN = qrcode;
flowStep = EGrrFlowStep.;
}
});
scanFail.ShowDialog();
//vProductResult.SN = VirtualBarCode.Code;
}
else
{
alarmEntity = AlarmCollection.Get(AlarmConstID.);
Msgbox.ShowDialog(alarmEntity, EButtonType.Retry, true);
}
}
else
{
alarmEntity = AlarmCollection.Get(AlarmConstID.);
Msgbox.ShowDialog(alarmEntity, EButtonType.Retry);
Msgbox.ShowDialog(alarmEntity, EButtonType.Retry, true);
}
}
else
{
alarmEntity = AlarmCollection.Get(AlarmConstID.);
Msgbox.ShowDialog(alarmEntity, EButtonType.Retry);
Msgbox.ShowDialog(alarmEntity, EButtonType.Retry, true);
}
}
else
catch (Exception ex)
{
alarmEntity = AlarmCollection.Get(AlarmConstID.);
Msgbox.ShowDialog(alarmEntity, EButtonType.Retry);
AlarmCollection.SystemExceptionAlarm(ex);
}
break;
case EGrrFlowStep.:
//获取空闲吸嘴

@ -1,517 +0,0 @@
using Rs.Controls;
using Rs.Framework;
using Rs.Motion;
using Rs.MotionPlat.Commom;
using Rs.MotionPlat.Entitys;
using Rs.MotionPlat.Flow.Common;
using Rs.MotionPlat.Flow.NormalFlow;
using Rs.MotionPlat.Flow.SafePosFlow;
using Rs.MotionPlat.Vision;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Rs.MotionPlat.Flow.SubFlow
{
enum EFiveProductTestFlowStep
{
OK,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
}
public class FiveProductTestFlow
{
private Task mainTask;
private FiveProductTestFlow() { }
private static FiveProductTestFlow instance;
public static FiveProductTestFlow Instance
{
get
{
if (instance == null)
{
instance = new FiveProductTestFlow();
}
return instance;
}
}
private AlarmEntity alarmEntity;
Stopwatch timeout = new Stopwatch();
EFiveProductTestFlowStep flowStep = EFiveProductTestFlowStep.OK;
int scanNum = 0;
string logInfo = string.Empty;
string alarmInfo = string.Empty;
private bool stop = true;
private bool run = true;
TargetPosition targetPosition = new TargetPosition();
ErrorCode errCode = ErrorCode.Ok;
/// <summary>
/// 当前取料穴位
/// </summary>
TraySlot curTakeSlot = null;
/// <summary>
/// 当前取料穴位的点位
/// </summary>
SlotPoint curTakeSlotPoint = null;
//Nozzle curNozzle = null;
Nozzle curTakeNozzle = null;
Nozzle curDumpNozzle = null;
TestFixture curFixture = null;
//放料穴位
TraySlot curDumpSlot = null;
/// <summary>
/// 最后一次换料的治具编号
/// </summary>
private int lastFixtureIndex = 0;
/// <summary>
/// 已经取走的产品数量
/// </summary>
private int takedNum = 0;
//相机拍照结果
VisionResult vResult = new VisionResult();
ProductLocationResult vProductResult = new ProductLocationResult();
List<TestFixture> needGrrFixtureList = new List<TestFixture>();
/// <summary>
/// 测试完成的数量
/// </summary>
private int testFinishedNum = 0;
private void Reset()
{
curTakeSlot = null;
curTakeSlotPoint = null;
curTakeNozzle = null;
curDumpNozzle = null;
curFixture = null;
curDumpSlot = null;
lastFixtureIndex = 0;
takedNum = 0;
testFinishedNum = 0;
VirtualBarCode.Reset();
}
bool binit = false;
public void Init()
{
if(binit)
{
return;
}
binit = true;
mainTask = new Task(Run);
mainTask.Start();
}
public void Deinit()
{
run = false;
}
int takeNum = 0;
private void Run()
{
while (run)
{
if (stop)
{
Thread.Sleep(10);
continue;
}
switch (flowStep)
{
#region 料仓取料
case EFiveProductTestFlowStep.OK:
ThreePointLocationFlow.Instance.Location(ETrayType.Ok);
flowStep = EFiveProductTestFlowStep.;
break;
case EFiveProductTestFlowStep.:
//GlobalTray.InputTray.ChangeStatus(1, ESlotStatus.Have);
//GlobalTray.InputTray.ChangeStatus(2, ESlotStatus.Have);
//GlobalTray.InputTray.ChangeStatus(3, ESlotStatus.Have);
//GlobalTray.InputTray.ChangeStatus(4, ESlotStatus.Have);
//GlobalTray.InputTray.ChangeStatus(5, ESlotStatus.Have);
curTakeSlot = GlobalTray.InputTray.GetSlot(ESlotStatus.Have);
if (curTakeSlot != null)
{
curTakeSlotPoint = TrayPointManager.GetSlotPoint(ETrayType.Input, curTakeSlot.Index);
if (curTakeSlotPoint != null)
{
targetPosition.X = curTakeSlotPoint.X;
targetPosition.Y1 = GlobalVar.StockSideY1;
targetPosition.Y2 = curTakeSlotPoint.Y;
//double curLoadX = Ops.GetCurPosition(AxisControl.LoadX);
//if (curLoadX - GlobalVar.FixtureSafePosX > 50)
//{
// DischargeModuleGoSafePosFlow.Instance.GoSafePostion(ESafePosSide.PlaceToStock);
//}
if (GroupAxisMove.XY1Y2MovePos(targetPosition, GlobalVar.WholeSpeed, EGoWhichSide.StockSide))
{
AxisPosPrint.PrintXY1Y2TargetPos("轴loadx,loady1,loady2已停止运动,", targetPosition, GetClassName());
flowStep = EFiveProductTestFlowStep.;
}
}
}
else
{
//没有料了,判断是否需要换料
GlobalTray.GrabTray.ChangeStatus(ESlotStatus.Have);
}
break;
case EFiveProductTestFlowStep.:
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 = EFiveProductTestFlowStep.;
}
else
{
flowStep = EFiveProductTestFlowStep.;
}
}
break;
case EFiveProductTestFlowStep.:
UpCameraHelper.Grab();
string msg = VisionHelper.OneGrabOne();//.Grab(EVisionScene.SingleScanBarcode);
vProductResult.Parse(msg);
if (vProductResult != null && (vProductResult.Result == EOneGrabSixteenResult.Ok || vProductResult.Result== EOneGrabSixteenResult.LocationOkScanBarcodeFail))
{
flowStep = EFiveProductTestFlowStep.;
}
else if (vProductResult != null && vProductResult.Result == EOneGrabSixteenResult.LocationOkScanBarcodeFail)
{
GrrScanFailFrm scanFail = new GrrScanFailFrm((act, qrcode) => {
if (act == 1)
{
vProductResult.SN = qrcode;
flowStep = EFiveProductTestFlowStep.;
}
});
scanFail.ShowDialog();
//vProductResult.SN = VirtualBarCode.Code;
}
else
{
alarmEntity = AlarmCollection.Get(AlarmConstID.);
Msgbox.ShowDialog(alarmEntity, EButtonType.Retry);
}
break;
case EFiveProductTestFlowStep.:
//获取空闲吸嘴
//curTakeNozzle = NozzleManager.GetIdelNozzle();
curTakeNozzle = NozzleManager.GetNozzle(1);
if (curTakeNozzle != null)
{
targetPosition = NozzleManager.GetToTraySlot(ETrayType.Input, curTakeSlot.Index, curTakeNozzle.NozzleIndex);
if (curTakeNozzle != null)
{
targetPosition.X += vProductResult.OffsetX + offsetX;
targetPosition.Y2 += vProductResult.OffsetY + offsetY;
if (GroupAxisMove.XY1Y2MovePos(targetPosition, GlobalVar.WholeSpeed, EGoWhichSide.StockSide))
{
AxisPosPrint.PrintXY1Y2TargetPos("到料仓取料位上方,", targetPosition, GetClassName());
flowStep = EFiveProductTestFlowStep.;
}
}
}
break;
case EFiveProductTestFlowStep.:
if (Ops.IsStop("LoadX", "LoadY1", "LoadY2") || GlobalVar.VirtualAxis)
{
AxisPosPrint.PrintXY1Y2CurrentPos("轴XY1Y2已停止运动,", GetClassName());
if (AxisArrived.LoadXY1Y2IsArrived(targetPosition.X, targetPosition.Y1, targetPosition.Y2))
{
AxisPosPrint.PrintXY1Y2CurrentPos("已运动到等待到料仓取料位上方,", GetClassName());
flowStep = EFiveProductTestFlowStep.;
}
else
{
flowStep = EFiveProductTestFlowStep.;
}
}
break;
case EFiveProductTestFlowStep.:
targetPosition.NozzleZ = NozzleManager.GetNozzleToTrayTakeProductPos(ETrayType.Input, curTakeNozzle.NozzleIndex);
errCode = AxisControl.GetAxis($"NozzleZ{curTakeNozzle.NozzleIndex}").MovePos(targetPosition.NozzleZ, GlobalVar.WholeSpeed);
if (errCode == ErrorCode.Ok)
{
logInfo = $"{GetClassName()}到料仓取料位下方";
MessageQueue.Instance.Insert(logInfo);
flowStep = EFiveProductTestFlowStep.;
}
break;
case EFiveProductTestFlowStep.:
if (Ops.IsStop($"NozzleZ{curTakeNozzle.NozzleIndex}"))
{
logInfo = $"{GetClassName()}已运动到料仓取料位下方";
MessageQueue.Instance.Insert(logInfo);
if (GlobalVar.RunSpace)
{
flowStep = EFiveProductTestFlowStep.;
}
else
{
Ops.On($"吸料真空{curTakeNozzle.NozzleIndex}吸");
Thread.Sleep(100);
flowStep = EFiveProductTestFlowStep.;
}
}
break;
case EFiveProductTestFlowStep.:
if (NozzleManager.GotoSafePos(curTakeNozzle.NozzleIndex))
{
logInfo = $"{GetClassName()}料仓取料完成抬起";
MessageQueue.Instance.Insert(logInfo);
flowStep = EFiveProductTestFlowStep.;
}
break;
case EFiveProductTestFlowStep.:
if (Ops.IsStop($"NozzleZ{curTakeNozzle.NozzleIndex}"))
{
logInfo = $"{GetClassName()}料仓取料完成已抬起";
MessageQueue.Instance.Insert(logInfo);
flowStep = EFiveProductTestFlowStep.;
}
break;
case EFiveProductTestFlowStep.:
if (Ops.IsOn($"吸料真空{curTakeNozzle.NozzleIndex}检测") || GlobalVar.RunSpace)
{
curTakeNozzle.Product = new TestProduct() { SN = "", FromSlotIndex = curTakeSlot.Index };
curTakeNozzle.Status = ENozzleStatus.ToUnload;
GlobalTray.NozzleTray.ChangeStatus(curTakeNozzle.NozzleIndex, ESlotStatus.Have);
GlobalTray.InputTray.ChangeStatus(curTakeSlot.Index, ESlotStatus.NotHave);
logInfo = $"{GetClassName()}料仓{curTakeSlot.Index}号穴位取料完成真空检测OK,产品SN:{curTakeNozzle.Product.SN}被吸嘴{curTakeNozzle.NozzleIndex}取走";
MessageQueue.Instance.Insert(logInfo);
flowStep = EFiveProductTestFlowStep.;
}
else
{
alarmEntity = AlarmCollection.Get(AlarmConstID.GRR);
Msgbox.ShowDialog(alarmEntity, EButtonType.Retry);
flowStep = EFiveProductTestFlowStep.;
}
break;
#endregion
//料仓放料
case EFiveProductTestFlowStep.:
//curDumpNozzle = NozzleManager.GetToUnloadNozzle();
curDumpNozzle = NozzleManager.GetNozzle(1);
if (curDumpNozzle != null)
{
//吸嘴放料,加测吸嘴上的产品的测试结果,决定把料放到哪个料仓
//目前先都方到OK料仓
//curDumpSlot = GlobalTray.GrrTray.GetSlot(ESlotStatus.NotHave);
curDumpSlot = GlobalTray.OkTary.GetSlot(ESlotStatus.NotHave);
if (curDumpSlot != null)
{
//double curLoadX = Ops.GetCurPosition(AxisControl.LoadX);
//if (curLoadX - GlobalVar.FixtureSafePosX > 50)
//{
// DischargeModuleGoSafePosFlow.Instance.GoSafePostion(ESafePosSide.PlaceToStock);
//}
targetPosition = NozzleManager.GetToTraySlot(ETrayType.Ok, curDumpSlot.Index, curDumpNozzle.NozzleIndex);
if (GroupAxisMove.XY1Y2MovePos(targetPosition, GlobalVar.WholeSpeed, EGoWhichSide.StockSide))
{
AxisPosPrint.PrintXY1Y2TargetPos("到料仓放料位上方,", targetPosition, GetClassName());
flowStep = EFiveProductTestFlowStep.;
}
}
else
{
GlobalTray.GrrTray.ChangeStatus(ESlotStatus.NotHave);
}
}
break;
case EFiveProductTestFlowStep.:
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 = EFiveProductTestFlowStep.;
}
else
{
flowStep = EFiveProductTestFlowStep.;
}
}
break;
case EFiveProductTestFlowStep.:
targetPosition.NozzleZ = NozzleManager.GetNozzleToTrayTakeProductPos(ETrayType.Ok, curDumpNozzle.NozzleIndex);
if (NozzleManager.Go(curDumpNozzle, targetPosition.NozzleZ, GlobalVar.WholeSpeed))
{
logInfo = $"{GetClassName()}到料仓放料位下方";
MessageQueue.Instance.Insert(logInfo);
flowStep = EFiveProductTestFlowStep.;
}
break;
case EFiveProductTestFlowStep.:
if (Ops.IsStop($"NozzleZ{curDumpNozzle.NozzleIndex}"))
{
logInfo = $"{GetClassName()}已运动到料仓放料位下方";
MessageQueue.Instance.Insert(logInfo);
if (GlobalVar.RunSpace)
{
flowStep = EFiveProductTestFlowStep.;
}
else
{
curDumpNozzle.VacSuction(EIoOperate.Close, GetClassName());
curDumpNozzle.VacBreak(EIoOperate.Open, GetClassName());
curDumpNozzle.VacBreak(EIoOperate.Close, GetClassName());
flowStep = EFiveProductTestFlowStep.;
}
}
break;
case EFiveProductTestFlowStep.:
if (NozzleManager.GotoSafePos(curDumpNozzle.NozzleIndex))
{
logInfo = $"{GetClassName()}料仓放料完成抬起";
MessageQueue.Instance.Insert(logInfo);
flowStep = EFiveProductTestFlowStep.;
}
break;
case EFiveProductTestFlowStep.:
if (Ops.IsStop($"NozzleZ{curDumpNozzle.NozzleIndex}"))
{
logInfo = $"{GetClassName()}料仓放料完成已抬起";
MessageQueue.Instance.Insert(logInfo);
takedNum++;
curDumpNozzle.Status = ENozzleStatus.IDLE;
GlobalTray.OkTary.ChangeStatus(curDumpSlot.Index, ESlotStatus.Have);
if (takedNum < 5)
{
flowStep = EFiveProductTestFlowStep.;
}
else
{
DischargeModuleGoSafePosFlow.Instance.GoSafePostion();
stop = true;
}
}
break;
}
Thread.Sleep(5);
}
}
public void Start()
{
GlobalTray.InputTray.ChangeStatus(1, ESlotStatus.Have);
GlobalTray.InputTray.ChangeStatus(2, ESlotStatus.Have);
GlobalTray.InputTray.ChangeStatus(3, ESlotStatus.Have);
GlobalTray.InputTray.ChangeStatus(4, ESlotStatus.Have);
GlobalTray.InputTray.ChangeStatus(5, ESlotStatus.Have);
GlobalTray.OkTary.ChangeStatus(1, ESlotStatus.NotHave);
GlobalTray.OkTary.ChangeStatus(2, ESlotStatus.NotHave);
GlobalTray.OkTary.ChangeStatus(3, ESlotStatus.NotHave);
GlobalTray.OkTary.ChangeStatus(4, ESlotStatus.NotHave);
GlobalTray.OkTary.ChangeStatus(5, ESlotStatus.NotHave);
flowStep = EFiveProductTestFlowStep.OK;
takedNum = 0;
stop = false;
}
public void Stop()
{
stop = true;
}
private string GetClassName()
{
return "GrrFlow-";
}
private double offsetX = 0;
private double offsetY = 0;
public void SetOffset(double x,double y)
{
offsetX = x;
offsetY = y;
}
/// <summary>
/// 获取吸嘴取料取不起来时,吸嘴在原取料位的偏移
/// 奇数向下偏移
/// 偶数向上偏移
/// </summary>
/// <param name="fetchNum"></param>
/// <returns></returns>
private double GetVacOffsetHeight(int fetchNum)
{
if (fetchNum == 0) return 0;
//先判断是奇数还是偶数
int count = 0;
int oddOrEven = fetchNum & 0x01;
double offsetDisct = 0.0;
if (oddOrEven == 1)
{
count = (fetchNum / 2) + 1;
offsetDisct = -0.1 * count;
}
else if (oddOrEven == 0)
{
count = (fetchNum / 2);
offsetDisct = 0.1 * count;
}
return offsetDisct;
}
public string GetCurStep()
{
return flowStep.ToString();
}
public void VirtualAxisSleep()
{
if (GlobalVar.VirtualAxis)
{
Thread.Sleep(GlobalVar.VirtualAxisMoveTime);
}
}
private void GotoNextFixture()
{
lastFixtureIndex = ((lastFixtureIndex + 1) % needGrrFixtureList.Count);
}
}
}

@ -41,7 +41,7 @@ namespace Rs.MotionPlat.Flow.SubFlow
bool finished = true;
EFixedGrabProductFlowStep step = EFixedGrabProductFlowStep.;
public ProductLocationResult TakePicture(ETrayType trayType,int slotInex,int grabNum=3)
public ProductLocationResult TakePicture(ETrayType trayType, int slotInex, int grabNum = 3, bool hasProdcutCheck = false)
{
ProductLocationResult result = new ProductLocationResult()
{
@ -119,42 +119,69 @@ namespace Rs.MotionPlat.Flow.SubFlow
}
break;
case EFixedGrabProductFlowStep.:
VisionHelper.oneGrabOneVision.ClearQueue();
UpCameraHelper.Grab();
string msg = VisionHelper.OneGrabOne();
result.Parse(msg);
//VisionResult vResult = VisionHelper.Grab(EVisionScene.SingleScanBarcode);
if ((result != null && result.Result== EOneGrabSixteenResult.Ok) || GlobalVar.RunSpace)
if (hasProdcutCheck)
{
finished = true;
if (GlobalVar.RunSpace)
VisionHelper.oneGrabOneVision.ClearQueue("C2");
UpCameraHelper.Grab();
string msg = VisionHelper.OneGrabOne("M2");
result.Parse(msg);
//VisionResult vResult = VisionHelper.Grab(EVisionScene.SingleScanBarcode);
if ((result != null && result.Result == EOneGrabSixteenResult.Ok) || GlobalVar.RunSpace)
{
result = new ProductLocationResult() { Result= EOneGrabSixteenResult.Ok};
finished = true;
if (GlobalVar.RunSpace)
{
result = new ProductLocationResult() { Result = EOneGrabSixteenResult.Ok };
}
return result;
}
else
{
finished = true;
return result;
}
return result;
}
else
{
if(curGrabNum<=3)
VisionHelper.oneGrabOneVision.ClearQueue("C");
UpCameraHelper.Grab();
string msg = VisionHelper.OneGrabOne("M");
result.Parse(msg);
//VisionResult vResult = VisionHelper.Grab(EVisionScene.SingleScanBarcode);
if ((result != null && result.Result == EOneGrabSixteenResult.Ok) || GlobalVar.RunSpace)
{
step = EFixedGrabProductFlowStep.;
LogHelper.Debug("result=ok");
finished = true;
if (GlobalVar.RunSpace)
{
result = new ProductLocationResult() { Result = EOneGrabSixteenResult.Ok };
}
return result;
}
else
{
AlarmEntity alarmEntity = AlarmCollection.Get(AlarmConstID.).Transform(grabSlot.Index);
// EButtonType btn = Msgbox.ShowDialog(alarmEntity, EButtonType.Retry| EButtonType.Cancel);
//if(btn== EButtonType.Retry)
//{
// curGrabNum = 1;
// step = EFixedGrabProductFlowStep.到拍照位上方;
//}
//else if(btn== EButtonType.Cancel)
LogHelper.Debug("result=ng");
if (curGrabNum <= 3)
{
step = EFixedGrabProductFlowStep.;
}
else
{
finished=true;
return result;
//AlarmEntity alarmEntity = AlarmCollection.Get(AlarmConstID.料仓取料拍照失败).Transform(grabSlot.Index);
// EButtonType btn = Msgbox.ShowDialog(alarmEntity, EButtonType.Retry| EButtonType.Cancel);
//if(btn== EButtonType.Retry)
//{
// curGrabNum = 1;
// step = EFixedGrabProductFlowStep.到拍照位上方;
//}
//else if(btn== EButtonType.Cancel)
{
finished = true;
return result;
}
}
curGrabNum++;
}
curGrabNum++;
}
break;
}

@ -135,6 +135,7 @@
<Compile Include="Commom\ActiveForms.cs" />
<Compile Include="Commom\AxisAlias.cs" />
<Compile Include="Commom\AxisPosPrint.cs" />
<Compile Include="Commom\BarCodeHelper.cs" />
<Compile Include="Commom\BinManager.cs" />
<Compile Include="Commom\BuzzerManager.cs" />
<Compile Include="Commom\DevLog.cs" />
@ -148,6 +149,7 @@
<Compile Include="Commom\Msgbox.cs" />
<Compile Include="Commom\MySqlHelper.cs" />
<Compile Include="Commom\ParameterInitAttribute.cs" />
<Compile Include="Commom\ScanFailNGHelper.cs" />
<Compile Include="Commom\TrayHelper.cs" />
<Compile Include="Commom\TrayRunPointManager.cs" />
<Compile Include="Commom\UpCameraHelper.cs" />
@ -164,7 +166,6 @@
<DependentUpon>DataRecords.cs</DependentUpon>
</Compile>
<Compile Include="Entitys\OneGrabSixteenManager.cs" />
<Compile Include="Flow\SubFlow\FiveProductTestFlow.cs" />
<Compile Include="Flow\SubFlow\OldTestFlow.cs" />
<Compile Include="Flow\SubFlow\StockGrabFlow.cs" />
<Compile Include="Flow\SubFlow\EnvironmentPrepareFlow.cs" />

@ -4,6 +4,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
@ -25,12 +26,13 @@ namespace Rs.MotionPlat.Vision
else
{
data = Encoding.ASCII.GetString(reciveBuffer.ToArray());
MessageQueue.Instance.Insert(data);
if (data == "M,0")
//MessageQueue.Instance.Insert(data);
if (data == "M,0" || data=="M2,0")
{
MessageQueue.Instance.Insert("视觉收到拍照指令");
MessageQueue.Instance.Insert($">>> {data}");
}
else if (data == "C,0")
//else if (Regex.IsMatch( data,"C\\d{0,1},0"))// == "C,0")
else if (data == "C,0" || data == "C2,0")
{
visionGrabEvent.Set();
MessageQueue.Instance.Insert($" >>> {data}");
@ -71,10 +73,10 @@ namespace Rs.MotionPlat.Vision
}
}
public bool ClearQueue(int timeout = 10000)
public bool ClearQueue(string cmd,int timeout = 10000)
{
visionGrabEvent.Reset();
string content = $"C;";
string content = $"{cmd};";
int len = vNozzleCalib.Send(content);
//reciveData = true;
if (len > 0)
@ -103,18 +105,19 @@ namespace Rs.MotionPlat.Vision
/// </summary>
/// <param name="timeout"></param>
/// <returns></returns>
public string OneGrabOne(int timeout = 10000)
public string OneGrabOne(string cmd,int timeout = 10000)
{
data = "";
result = null;
NozzleCalibReciveEvent.Reset();
int len = vNozzleCalib.Send("M;");
int len = vNozzleCalib.Send($"{cmd};");
LogHelper.Debug($"<<< {cmd};len={len}");
if (len > 0)
{
if (NozzleCalibReciveEvent.WaitOne(timeout))
{
MessageQueue.Instance.Insert($"收到视觉结果:{data}");
MessageQueue.Instance.Insert($">>> {data}");
return data;
}
else

@ -85,9 +85,9 @@ namespace Rs.MotionPlat.Commom
}
public static string OneGrabOne()
public static string OneGrabOne(string cmd)
{
return oneGrabOneVision.OneGrabOne();
return oneGrabOneVision.OneGrabOne(cmd);
}
}
}

Loading…
Cancel
Save