Commit 927669a5 张东亮

添加一维码检测料盘

1 个父辈 fa2cad7b
...@@ -263,6 +263,96 @@ namespace DeviceLibrary ...@@ -263,6 +263,96 @@ namespace DeviceLibrary
string logtxt = $"【" + cameraName + "】开始取图片测试是否有料盘" + "\r\n"; string logtxt = $"【" + cameraName + "】开始取图片测试是否有料盘" + "\r\n";
DateTime startTime = DateTime.Now; DateTime startTime = DateTime.Now;
Bitmap bmp = null; Bitmap bmp = null;
bool usebarcode = ConfigHelper.Config.Get("CamTestReel_useBarcode", false);
if (usebarcode)
{
try
{
//bmp = new Bitmap(@"D:\logs\10-30-51-138.bmp");
bmp = Camera._cam.GrabOne(cameraName);
if (bmp == null)
{
if (retrytime > 2)
return null;
retrytime++;
Camera._cam.Close(cameraName);
//LoadCamera(true);
LogUtil.info($"bitmap为空重试第{retrytime}次");
Thread.Sleep(2000);
goto retry;
}
logtxt += $"【" + cameraName + "】获取到图像" + "\r\n";
string code = ConfigHelper.Config.Get("CamTestReel_barcode", "RW0000015");
int codeThreshold = ConfigHelper.Config.Get("CamTestReel_barcodeThreshold", 2);
if (ConfigHelper.Config.Get("CamTestReel_debug", false))
srcimg = SaveImageToFile("test", cameraName, bmp);
bool hasReel = false;
RemoteDecodeHelper.RemoteDecodeParam remoteDecodeParam = new RemoteDecodeHelper.RemoteDecodeParam
{
codeTypeList = codeTypeList.ToArray(),
codeCount = QRCodeCount,
timeout = CodeTimeOut
};
List<CodeInfo> cc = RemoteDecodeHelper.DecodeRequest(bmp, remoteDecodeParam);
int count = 0;
if (cc == null) hasReel = true;
else
{
var res = cc.FindAll(s => code.Equals(s.CodeStr));
count = res.Count();
if (res == null || count < codeThreshold)
{
hasReel = true;
}
}
string r = "";
if (cc != null && cc.Count > 0)
{
cc.ForEach((c) =>
{
c.CodeStr = CodeManager.ReplaceCode(c.CodeStr);
r += "#" + c.CodeStr;
});
}
logtxt += $" 一维码扫描结果:{count}[{r}],设置可扫描到条码数量:{codeThreshold},result:{((count < codeThreshold)?"有料":"无料")}\r\n";
if (hasReel != lastHasReel)
{
lastHasReel = hasReel;
}
else if (!ConfigHelper.Config.Get("CamTestReel_debug", false))
logtxt = "";
if (ConfigHelper.Config.Get("CamTestReel_debug", false) || (TestHasRight.HasValue && TestHasRight.Value != hasReel))
prcimg = SaveImageToFile("test2", cameraName, bmp);
TestHasRight = null;
return hasReel;
}
catch (AccessViolationException e)
{
LogUtil.error(" 扫码出现AccessViolationException异常,关闭相机【" + cameraName + "】:" + e.ToString());
Camera._cam.Close(cameraName);
return null;
}
catch (Exception ex)
{
LogUtil.error(" 扫码出错:" + ex.ToString());
return null;
}
finally
{
if (bmp != null)
bmp.Dispose();
if (!string.IsNullOrEmpty(logtxt))
LogUtil.error(logtxt);
Monitor.Exit(testLocObj);
}
}
else
{
try try
{ {
//bmp = new Bitmap(@"D:\logs\10-30-51-138.bmp"); //bmp = new Bitmap(@"D:\logs\10-30-51-138.bmp");
...@@ -407,10 +497,12 @@ namespace DeviceLibrary ...@@ -407,10 +497,12 @@ namespace DeviceLibrary
if (bmp != null) if (bmp != null)
bmp.Dispose(); bmp.Dispose();
if (!string.IsNullOrEmpty(logtxt)) if (!string.IsNullOrEmpty(logtxt))
LogUtil.error(logtxt); LogUtil.info(logtxt);
Monitor.Exit(testLocObj); Monitor.Exit(testLocObj);
} }
} }
}
else else
return null; return null;
} }
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!