Commit c3abc9bf 张东亮

视觉检测料盘、最后一盘自增可配置

1 个父辈 b0174c0e
using CodeLibrary;
using log4net.Util;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
......@@ -268,6 +269,84 @@ namespace OnlineStore.DeviceLibrary
}
return codeList;
}
[HandleProcessCorruptedStateExceptions]
public static bool CameraCheckHeight(List<string> cameraList, string deviceName, bool findRightCodeBreak = false, int timeOut = 1500)
{
bool isPreScan = deviceName.EndsWith("预扫码");
isPreScan = false;
List<string> codeList = new List<string>();
if (cameraList == null || cameraList.Count <= 0)
{
return false;
}
try
{
foreach (string cameraName in cameraList)
{
if (cameraName.Trim().Equals(""))
{
continue;
}
ScanCount++;
DateTime startTime = DateTime.Now;
if (deviceName != "")
{
LogUtil.info(deviceName + " 【" + cameraName + "】开始取图片");
}
Bitmap bmp = null;
HalconDotNet.HObject ho_Image = null;
try
{
ho_Image = Camera._cam.CaptureOnImage(cameraName, out bmp);
if (ho_Image == null)
{
LogUtil.error(deviceName + " 【" + cameraName + "】取图片失败[" + Camera._cam.ErrInfo + "],关闭相机");
CloseCamera(cameraName);
continue;
}
else
{
LogUtil.info(deviceName + " 【" + cameraName + "】取图片完成");
return true;
}
}
catch (AccessViolationException e)
{
LogUtil.error(deviceName + " 扫码出现AccessViolationException异常,关闭相机【" + cameraName + "】:" + e.ToString());
Camera._cam.Close(cameraName);
// GC.Collect();
}
catch (Exception ex)
{
LogUtil.error(deviceName + " 扫码出错:" + ex.ToString());
}
finally
{
if (ho_Image != null)
{
ho_Image.Dispose();
ho_Image = null;
}
// GC.Collect();
Task.Delay(10);
}
}
}
catch (AccessViolationException e)
{
LogUtil.error(deviceName + " 扫码出现AccessViolationException异常,关闭所有相机:" + e.ToString());
Camera._cam.CloseAll();
//GC.Collect();
}
catch (Exception ex)
{
LogUtil.error(deviceName + " 扫码出错:" + ex.ToString());
}
return false;
}
private static int SaveErrorImageToFile = ConfigAppSettings.GetIntValue(Setting_Init.SaveErrorImageToFile);
//private static void SaveImageToFile(string deviceName, string cameraName, HalconDotNet.HObject bitmap)
......
......@@ -61,7 +61,7 @@ namespace OnlineStore.DeviceLibrary
Config.LoadIO(ioAdd);
MoveInfo = new DeviceMoveInfo(Name);
cames = ConfigHelper.Config.Get<string[]>($"{Name}_HeightCams");
}
public void TimerProcess()
{
......
......@@ -400,7 +400,8 @@ namespace OnlineStore.DeviceLibrary
//else
if (isScan)
{
WorkLog("料盘移栽 :开始扫码");
WorkLog("料盘移栽 :开始扫码,并采集抓取前测高图片");
CodeManager.CameraCheckHeight(cames?.ToList(), Name);
MoveInfo.OneWaitCanEndStep = true;
MoveInfo.WaitList.Add(WaitResultInfo.WaitFeedScanCode());
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(60000));
......@@ -556,8 +557,12 @@ namespace OnlineStore.DeviceLibrary
public int StartMovePosition = 0;
public int EndMovePosition = 0;
internal int LastHeight = 0;
string[] cames;
public int GetHeight()
{
CodeManager.CameraCheckHeight(cames?.ToList(), Name);
LogUtil.info($"{Name} 采集料盘抓走后的图片,开始计算高度");
int lastReelAddVal = ConfigHelper.Config.Get($"{Name}_lastReelSelfAddVal", 4);
LastHeight = 0;
int AxisChangeValue = Robot.Config.Height_ChangeValue;
//计算高度
......@@ -572,8 +577,8 @@ namespace OnlineStore.DeviceLibrary
string buchongStr = "";
if (isLast)
{
buchongStr = "(最后一盘料)加4";
height += 4;
buchongStr = $"(最后一盘料)加{lastReelAddVal}";
height += lastReelAddVal;
}
//如果检测出<=15,都按照8计算
......@@ -608,8 +613,11 @@ namespace OnlineStore.DeviceLibrary
}
if (LastHeight <= 8) { LastHeight = 8; }
string code = CodeManager.ProcessCode(LastCodeList);
string msg = Name + " 计算盘高:上升前 [" + StartMovePosition + "]实时[ " + EndMovePosition + "]差值[" + (EndMovePosition - StartMovePosition) + "]系数[" + AxisChangeValue + "] 计算后" + buchongStr + "[" + height + "]" + ",归类为【" + LastHeight + "mm】条码【" + code + "】";
Thread.Sleep(500);
string msg = $"{Name} 上升前 [{StartMovePosition}]实时[{ EndMovePosition}]差值[{(EndMovePosition - StartMovePosition)}]" +
$"系数[{AxisChangeValue}] 计算后{buchongStr}[{height}]条码【{code}】";
LogUtil.info(msg);
LogUtil.info($"{Name} 视觉计算的盘高结果:{height}mm,归类为{LastHeight}mm");
return LastHeight;
}
#endregion
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!