Commit bf13997a 刘韬

优化haobo_v2图像获取时的等待锁

1 个父辈 0faaa9d2
...@@ -259,7 +259,7 @@ namespace Asa ...@@ -259,7 +259,7 @@ namespace Asa
if (!string.IsNullOrEmpty(tf)) if (!string.IsNullOrEmpty(tf))
type = "ID_TYPE_T"; type = "ID_TYPE_T";
var result = NeoX.AlgoC(path, tf, ShrinkOffset,0, type, out int c, out Bitmap bitmap, out errmsg); var result = NeoX.AlgoC(path, tf, ShrinkOffset,0, type, out int c, out Bitmap bitmap, out errmsg);
errmsg += errmsg2; errmsg += "errmsg2:" + errmsg2;
count = new int[4] { c, 0, 0, 0 }; count = new int[4] { c, 0, 0, 0 };
BmpDstImg = bitmap; BmpDstImg = bitmap;
return result?0:-1; return result?0:-1;
...@@ -306,9 +306,13 @@ namespace Asa ...@@ -306,9 +306,13 @@ namespace Asa
// 检查目标文件是否存在 // 检查目标文件是否存在
if (File.Exists(fullPath)) if (File.Exists(fullPath))
{ {
debugstr = "fullPath Exists:" + fullPath;
return fullPath; // 返回文件的完整路径 return fullPath; // 返回文件的完整路径
}else if (File.Exists(subfullPath))
}
else if (File.Exists(subfullPath))
{ {
debugstr = "subfullPath Exists:" + fullPath;
return subfullPath; // 返回文件的完整路径 return subfullPath; // 返回文件的完整路径
} }
else else
......
using Asa.HaoboSDK_v2; using Asa.HaoboSDK_v2;
using ConfigHelper; using ConfigHelper;
using System; using System;
using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Drawing.Imaging;
using System.IO; using System.IO;
using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
...@@ -24,14 +21,15 @@ namespace Asa ...@@ -24,14 +21,15 @@ namespace Asa
ImageData imagedata; ImageData imagedata;
//ImageBuff imgbuff = new ImageBuff();// 共用体 // ushort[] imagetemp; //ImageBuff imgbuff = new ImageBuff();// 共用体 // ushort[] imagetemp;
byte[] buffer; byte[] buffer;
public haobo_v2(string logName = "CarerayImage") { public haobo_v2(string logName = "CarerayImage")
{
LOG = log4net.LogManager.GetLogger(logName); LOG = log4net.LogManager.GetLogger(logName);
LOG.Info("Load haobo_v2"); LOG.Info("Load haobo_v2");
//1 初始化DLL //1 初始化DLL
HBI_FPD_DLL._handel = HBI_FPD_DLL.HBI_Init(); HBI_FPD_DLL._handel = HBI_FPD_DLL.HBI_Init();
_dUserCallbackHandleEnvent = hbiMainCallBackFun; _dUserCallbackHandleEnvent = hbiMainCallBackFun;
//2 注册回调函数 //2 注册回调函数
int _ret = HBI_FPD_DLL.HBI_RegEventCallBackFun(HBI_FPD_DLL._handel, _dUserCallbackHandleEnvent,IntPtr.Zero); int _ret = HBI_FPD_DLL.HBI_RegEventCallBackFun(HBI_FPD_DLL._handel, _dUserCallbackHandleEnvent, IntPtr.Zero);
if (_ret != 0) WriteLog("HBI_RegEventCallBackFun:" + GetHbiError(_ret)); if (_ret != 0) WriteLog("HBI_RegEventCallBackFun:" + GetHbiError(_ret));
} }
...@@ -90,13 +88,15 @@ namespace Asa ...@@ -90,13 +88,15 @@ namespace Asa
} }
return _ret == 0; return _ret == 0;
} }
string GetHbiError(int errcode) { string GetHbiError(int errcode)
{
try try
{ {
HBIRETCODE hBIRETCODE = (HBIRETCODE)errcode; HBIRETCODE hBIRETCODE = (HBIRETCODE)errcode;
HbiError.CrErrStrList.TryGetValue(hBIRETCODE, out string errmsg); HbiError.CrErrStrList.TryGetValue(hBIRETCODE, out string errmsg);
return hBIRETCODE + "," + errmsg; return hBIRETCODE + "," + errmsg;
}catch (Exception e) }
catch (Exception e)
{ {
return errcode + "," + e; return errcode + "," + e;
} }
...@@ -260,7 +260,6 @@ namespace Asa ...@@ -260,7 +260,6 @@ namespace Asa
return (windowWidth, windowCenter); return (windowWidth, windowCenter);
} }
volatile bool buffgetted = false;
ManualResetEventSlim buffgettedEvt = new ManualResetEventSlim(false); ManualResetEventSlim buffgettedEvt = new ManualResetEventSlim(false);
int getpiccount = 0; int getpiccount = 0;
public bool GetImage(int _MaxFrameCount = 3, int MaxDelay = 5000) public bool GetImage(int _MaxFrameCount = 3, int MaxDelay = 5000)
...@@ -281,14 +280,14 @@ namespace Asa ...@@ -281,14 +280,14 @@ namespace Asa
//} //}
WriteLog("GetImage start========================"); WriteLog("GetImage start========================");
getpiccount = _MaxFrameCount; getpiccount = _MaxFrameCount;
buffgetted = false;
buffgettedEvt.Reset(); buffgettedEvt.Reset();
int ret = HBI_FPD_DLL.HBI_SinglePrepare(HBI_FPD_DLL._handel); //5 int ret = HBI_FPD_DLL.HBI_SinglePrepare(HBI_FPD_DLL._handel); //5
if (ret != 0) WriteLog("HBI_SinglePrepare:" + GetHbiError(ret)); if (ret != 0) WriteLog("HBI_SinglePrepare:" + GetHbiError(ret));
else WriteLog("0x02 prepare成功"); else WriteLog("0x02 prepare成功");
buffgettedEvt.Wait(TimeSpan.FromMilliseconds(MaxDelay)); var isintime = buffgettedEvt.Wait(TimeSpan.FromMilliseconds(MaxDelay));
WriteLog("GetImage end =" + isintime + "=======================");
/* /*
if (buffer != null) if (buffer != null)
{ {
...@@ -549,9 +548,12 @@ namespace Asa ...@@ -549,9 +548,12 @@ namespace Asa
// 当前反馈固件参数,转化为结构体 add by mhyang 20220402 // 当前反馈固件参数,转化为结构体 add by mhyang 20220402
imagedata = (ImageData)Marshal.PtrToStructure(ptrParam1, typeof(ImageData)); imagedata = (ImageData)Marshal.PtrToStructure(ptrParam1, typeof(ImageData));
#if !savebmp8 // 正常按照16bit图像显示,add by mhyang 20220615 #if !savebmp8 // 正常按照16bit图像显示,add by mhyang 20220615
if (SaveImage() == 0) // 保存 if (SaveImage() == 1) // 保存
{
buffgettedEvt.Set();
}
else
{ {
buffgetted = true;
buffgettedEvt.Set(); buffgettedEvt.Set();
} }
#else // 按照8bit图像显示,add by mhyang 20221104 #else // 按照8bit图像显示,add by mhyang 20221104
...@@ -996,7 +998,8 @@ namespace Asa ...@@ -996,7 +998,8 @@ namespace Asa
// //
return 1; return 1;
} }
catch (Exception ex) { catch (Exception ex)
{
WriteLog($"SaveImage fail:{ex}\n"); WriteLog($"SaveImage fail:{ex}\n");
} }
return 0; return 0;
...@@ -1050,7 +1053,8 @@ namespace Asa ...@@ -1050,7 +1053,8 @@ namespace Asa
if (ret != 0) if (ret != 0)
return false; return false;
if (mode == 2) { if (mode == 2)
{
downloadStatus = 0; //下载前置0 downloadStatus = 0; //下载前置0
// 第二步:注册回调函数 // 第二步:注册回调函数
ret = HBI_FPD_DLL.HBI_RegProgressCallBack(HBI_FPD_DLL._handel, DownloadCallBack, IntPtr.Zero); ret = HBI_FPD_DLL.HBI_RegProgressCallBack(HBI_FPD_DLL._handel, DownloadCallBack, IntPtr.Zero);
...@@ -1070,12 +1074,14 @@ namespace Asa ...@@ -1070,12 +1074,14 @@ namespace Asa
WriteLog("HBI_DownloadTemplateByType:gain template failed!ret:[{0}]:" + GetHbiError(ret)); WriteLog("HBI_DownloadTemplateByType:gain template failed!ret:[{0}]:" + GetHbiError(ret));
return false; return false;
} }
for (int i=0;i<30;i++){ for (int i = 0; i < 30; i++)
{
if (downloadStatus == 0) if (downloadStatus == 0)
{ {
Task.Delay(1000).Wait(); Task.Delay(1000).Wait();
} }
else { else
{
if (downloadStatus == 1) if (downloadStatus == 1)
{ {
WriteLog("模版下载成功"); WriteLog("模版下载成功");
...@@ -1209,7 +1215,8 @@ namespace Asa ...@@ -1209,7 +1215,8 @@ namespace Asa
return 1; return 1;
} }
void WriteLog(string log) { void WriteLog(string log)
{
LOG.Info(log); LOG.Info(log);
} }
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!