配合视觉优化飞拍逻辑,边运动边解析

master
lhiven 8 months ago
parent b4362c1091
commit b764682527

@ -7,6 +7,7 @@ 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.Tasks;
@ -52,6 +53,7 @@ namespace Rs.MotionPlat.Flow.SubFlow
finished = false;
else
return;
Stopwatch stopwatch = Stopwatch.StartNew();
flowStep = EProductLocationFlowStep.;
string logInfo = string.Empty;
TargetPosition targetPosition = new TargetPosition();
@ -148,6 +150,7 @@ namespace Rs.MotionPlat.Flow.SubFlow
if (AxisArrived.LoadXY1Y2IsArrived(targetPosition.X, targetPosition.Y1, targetPosition.Y2))
{
AxisPosPrint.PrintXY1Y2CurrentPos("已运动到料仓拍照结束位,", GetClassName());
stopwatch.Restart();
flowStep = EProductLocationFlowStep.;
}
else
@ -166,38 +169,56 @@ namespace Rs.MotionPlat.Flow.SubFlow
}
else
{
string vmsg = VisionHelper.loadTakeProductVision.OneGrabSixteen(10000);
string[] msgs = vmsg.Split(new string[] { "#," }, StringSplitOptions.RemoveEmptyEntries);
//if (!string.IsNullOrEmpty(vmsg)&& vmsg.TrimEnd(new char[] { '#', ',' }).Split('#').Length==16)
if (!string.IsNullOrEmpty(vmsg) && msgs.Length == 16)
if (stopwatch.ElapsedMilliseconds<10000)
{
List<string> snList = new List<string>();
foreach (string msg in msgs)
if (VisionHelper.loadTakeProductVision.Num == 16)
{
string[] items = msg.Split(new char[] { ',' });
if (items[1] == "0")
string vmsg = VisionHelper.loadTakeProductVision.OneGrabSixteen(10000);
if(vmsg != null)
{
snList.Add(items[2]);
}
}
if (snList.GroupBy(a => a).Where(k => k.Count() >= 2).Count() == 0)
{
reTakePicNum = 0;
OneGrabSixteenManager.Instance.ParseResult(vmsg, slotIndex);
finished = true;
}
else
{
MessageQueue.Instance.Warn("Duplicate barcode");
reTakePicNum++;
if (reTakePicNum > 4)
{
Msgbox.ShowTipDialog(EButtonType.Retry, "Duplicate barcode alarm", "alarm", true);
reTakePicNum = 0;
string[] msgs = vmsg.Split(new string[] { "#," }, StringSplitOptions.RemoveEmptyEntries);
//if (!string.IsNullOrEmpty(vmsg)&& vmsg.TrimEnd(new char[] { '#', ',' }).Split('#').Length==16)
if (!string.IsNullOrEmpty(vmsg) && msgs.Length == 16)
{
List<string> snList = new List<string>();
foreach (string msg in msgs)
{
string[] items = msg.Split(new char[] { ',' });
if (items[1] == "0")
{
snList.Add(items[2]);
}
}
if (snList.GroupBy(a => a).Where(k => k.Count() >= 2).Count() == 0)
{
reTakePicNum = 0;
OneGrabSixteenManager.Instance.ParseResult(vmsg, slotIndex);
finished = true;
}
else
{
MessageQueue.Instance.Warn("Duplicate barcode");
reTakePicNum++;
if (reTakePicNum > 4)
{
Msgbox.ShowTipDialog(EButtonType.Retry, "Duplicate barcode alarm", "alarm", true);
reTakePicNum = 0;
}
flowStep = EProductLocationFlowStep.;
}
}
else
{
alarmEntity = AlarmCollection.Get(AlarmConstID.);
Msgbox.ShowDialog(alarmEntity, EButtonType.Retry, true);
//Msgbox.ShowTipDialog(EButtonType.Retry, "一拍十六拍照失败,请处理后点击重试","grab fail",true);
flowStep = EProductLocationFlowStep.;
}
}
flowStep = EProductLocationFlowStep.;
}
}
else
{
@ -206,6 +227,7 @@ namespace Rs.MotionPlat.Flow.SubFlow
//Msgbox.ShowTipDialog(EButtonType.Retry, "一拍十六拍照失败,请处理后点击重试","grab fail",true);
flowStep = EProductLocationFlowStep.;
}
}
break;
}

@ -7,6 +7,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
@ -17,6 +18,7 @@ namespace Rs.MotionPlat.Vision
/// </summary>
public class LoadTakeProductVision:BaseVision
{
public int Num { get; set; } = 0;
string data = string.Empty;
static int visionNum = 4;
static ManualResetEvent visionGrabEvent = new ManualResetEvent(false);
@ -29,12 +31,13 @@ namespace Rs.MotionPlat.Vision
//所有的视觉数据以;作为结束符
foreach (byte b in arg2)
{
if (b != 59)
if (b != ';')
{
reciveBuffer.Add(b);
}
else
{
data = Encoding.ASCII.GetString(reciveBuffer.ToArray());
//MessageQueue.Instance.Insert(data);
if (data == "M,0")
@ -45,6 +48,14 @@ namespace Rs.MotionPlat.Vision
{
visionGrabEvent.Set();
}
else if(Regex.IsMatch(data,"M,\\d{0,2}F"))
{
Num++;
if(Num==16)
{
reciveData = false;
}
}
else
{
visionGrabEvent.Set();
@ -105,6 +116,7 @@ namespace Rs.MotionPlat.Vision
public bool ClearQueue(int timeout = 10000)
{
Num = 0;
visionGrabEvent.Reset();
int len = vNozzleCalib.Send("C;");
reciveData = true;
@ -112,7 +124,7 @@ namespace Rs.MotionPlat.Vision
{
if (visionGrabEvent.WaitOne(timeout))
{
reciveData = false;
//reciveData = false;
MessageQueue.Instance.Insert($"收到视觉结果:{data}");
return true;
}

Loading…
Cancel
Save