Commit d963703c LN

1

1 个父辈 26df9ae0
...@@ -145,6 +145,8 @@ class NanjingSDotIO : IOBase ...@@ -145,6 +145,8 @@ class NanjingSDotIO : IOBase
/// <returns></returns> /// <returns></returns>
public bool WriteDO(int donum, bool state) public bool WriteDO(int donum, bool state)
{ {
try
{
byte funCode = 0x0F;//批量写圈 byte funCode = 0x0F;//批量写圈
byte startAddress = (byte)(64 + donum);//写圈起始地址 byte startAddress = (byte)(64 + donum);//写圈起始地址
byte startLength = 1; byte startLength = 1;
...@@ -205,8 +207,15 @@ class NanjingSDotIO : IOBase ...@@ -205,8 +207,15 @@ class NanjingSDotIO : IOBase
var output = string.Join(" ", newResult.Select(x => x.ToString("X2"))); var output = string.Join(" ", newResult.Select(x => x.ToString("X2")));
*/ */
return check; return check;
} }
catch (Exception ex)
{
TSA_V.Common.LogUtil.error("出错:" + ex.ToString());
}
return false;
}
/// <summary> /// <summary>
/// 所有DI状态 /// 所有DI状态
/// </summary> /// </summary>
......
...@@ -172,33 +172,58 @@ namespace TSA_V ...@@ -172,33 +172,58 @@ namespace TSA_V
} }
DateTime startTime = DateTime.Now; DateTime startTime = DateTime.Now;
LogUtil.info("AOICheck : 开始获取图片"); LogUtil.info("AOICheck : 开始获取图片");
Image currImage = CameraManager.GetCamerImage(camera); string theImagePath = "";
using (Bitmap currImage = CameraManager.GetCamerImage(camera))
{
if (currImage == null) if (currImage == null)
{ {
string file = defFile; string file = defFile;
if (File.Exists(file)) if (File.Exists(file))
{ {
//从本地加载图片 theImagePath = file;
Bitmap aa = new Bitmap(file); ////从本地加载图片
currImage = ImageManager.DeepClone(aa); //Bitmap aa = new Bitmap(file);
//currImage = ImageManager.DeepClone(aa);
} }
} }
if (currImage != null) if (currImage != null)
{ {
TimeSpan span1 = DateTime.Now - startTime;
LogUtil.info($"AOICheck : 图片获取完成, {Math.Round( span1.TotalMilliseconds,1)}ms, 开始check");
if (Setting_NInit.Work_SaveAOIImg) if (Setting_NInit.Work_SaveAOIImg)
{ {
ImageUtilM.SaveImageToFile("AOI","Source",Eyemlib.DeepClone(currImage)); theImagePath = ImageUtilM.SaveImageToFile("AOI", "Source", currImage);
}
else
{
string filePath = Application.StartupPath + @"\image\";
Directory.CreateDirectory(filePath);
string fileName = @"\test.bmp";
string path = Path.GetFullPath(filePath);
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
} }
theImagePath = filePath + fileName;
currImage.Save(filePath + fileName, ImageFormat.Bmp);
}
}
}
if (theImagePath != "" && File.Exists(theImagePath))
{
TimeSpan span1 = DateTime.Now - startTime;
LogUtil.info($"AOICheck : 图片获取{theImagePath}完成, {Math.Round(span1.TotalMilliseconds, 1)}ms, 开始check");
var bmp = new Bitmap(theImagePath);
Image TestImage = Eyemlib.DeepClone(bmp);
bmp.Dispose();
//Bitmap bitmap = new Bitmap(currImage); //Bitmap bitmap = new Bitmap(currImage);
Image outImage = null; Image outImage = null;
List<ResultBean> resultBean = CurrProject.CheckAll(currImage, out outImage); List<ResultBean> resultBean = CurrProject.CheckAll(TestImage, out outImage);
span1 = DateTime.Now - startTime; span1 = DateTime.Now - startTime;
LogUtil.info($"AOICheck : check完成, {Math.Round(span1.TotalMilliseconds, 1)}ms"); LogUtil.info($"AOICheck : check完成, {Math.Round(span1.TotalMilliseconds, 1)}ms");
currImage.Dispose();
ResultList = resultBean; ResultList = resultBean;
if (outImage != null) if (outImage != null)
{ {
...@@ -210,7 +235,7 @@ namespace TSA_V ...@@ -210,7 +235,7 @@ namespace TSA_V
} }
else else
{ {
this.picResult.Image = currImage; this.picResult.Image = Eyemlib.DeepClone(TestImage);
} }
result = 1; result = 1;
endTime = DateTime.Now; endTime = DateTime.Now;
...@@ -224,7 +249,8 @@ namespace TSA_V ...@@ -224,7 +249,8 @@ namespace TSA_V
result = 2; result = 2;
// break; // break;
listErrorView.Items.Add(GetShowName(bean)); listErrorView.Items.Add(GetShowName(bean));
}else if (chbAllShow.Checked) }
else if (chbAllShow.Checked)
{ {
listErrorView.Items.Add(GetShowName(bean)); listErrorView.Items.Add(GetShowName(bean));
...@@ -232,13 +258,13 @@ namespace TSA_V ...@@ -232,13 +258,13 @@ namespace TSA_V
} }
if (listErrorView.Items.Count > 0) if (listErrorView.Items.Count > 0)
{ {
listErrorView.Items[0].Selected = true ; listErrorView.Items[0].Selected = true;
} }
chbAllShow.Enabled = true; chbAllShow.Enabled = true;
if (result.Equals(1)) if (result.Equals(1))
{ {
lblError.Visible = false ; lblError.Visible = false;
lblInfo.Text = AccAOI.ControlUtil.GetResultsStr(resultBean); lblInfo.Text = AccAOI.ControlUtil.GetResultsStr(resultBean);
lblInfo.Visible = true; lblInfo.Visible = true;
LogUtil.info("AOI检测OK:" + lblInfo.Text); LogUtil.info("AOI检测OK:" + lblInfo.Text);
...@@ -250,6 +276,7 @@ namespace TSA_V ...@@ -250,6 +276,7 @@ namespace TSA_V
lblError.Visible = true; lblError.Visible = true;
LogUtil.info("AOI检测NG:" + ngList); LogUtil.info("AOI检测NG:" + ngList);
} }
TestImage.Dispose();
} }
else else
{ {
...@@ -258,7 +285,7 @@ namespace TSA_V ...@@ -258,7 +285,7 @@ namespace TSA_V
LogUtil.error("AOI检测:获取相机图片失败:" + CameraManager.ErrorMsg); LogUtil.error("AOI检测:获取相机图片失败:" + CameraManager.ErrorMsg);
return 0; return 0;
} }
chbAllShow.Enabled = true ; chbAllShow.Enabled = true;
} }
catch (AccessViolationException e) catch (AccessViolationException e)
{ {
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!