Commit bf13997a 刘韬

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

1 个父辈 0faaa9d2
......@@ -259,7 +259,7 @@ namespace Asa
if (!string.IsNullOrEmpty(tf))
type = "ID_TYPE_T";
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 };
BmpDstImg = bitmap;
return result?0:-1;
......@@ -306,9 +306,13 @@ namespace Asa
// 检查目标文件是否存在
if (File.Exists(fullPath))
{
debugstr = "fullPath Exists:" + fullPath;
return fullPath; // 返回文件的完整路径
}else if (File.Exists(subfullPath))
}
else if (File.Exists(subfullPath))
{
debugstr = "subfullPath Exists:" + fullPath;
return subfullPath; // 返回文件的完整路径
}
else
......
using Asa.HaoboSDK_v2;
using ConfigHelper;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
......@@ -24,14 +21,15 @@ namespace Asa
ImageData imagedata;
//ImageBuff imgbuff = new ImageBuff();// 共用体 // ushort[] imagetemp;
byte[] buffer;
public haobo_v2(string logName = "CarerayImage") {
public haobo_v2(string logName = "CarerayImage")
{
LOG = log4net.LogManager.GetLogger(logName);
LOG.Info("Load haobo_v2");
//1 初始化DLL
HBI_FPD_DLL._handel = HBI_FPD_DLL.HBI_Init();
_dUserCallbackHandleEnvent = hbiMainCallBackFun;
//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));
}
......@@ -90,13 +88,15 @@ namespace Asa
}
return _ret == 0;
}
string GetHbiError(int errcode) {
string GetHbiError(int errcode)
{
try
{
HBIRETCODE hBIRETCODE = (HBIRETCODE)errcode;
HbiError.CrErrStrList.TryGetValue(hBIRETCODE, out string errmsg);
return hBIRETCODE + "," + errmsg;
}catch (Exception e)
}
catch (Exception e)
{
return errcode + "," + e;
}
......@@ -192,11 +192,11 @@ namespace Asa
Bitmap bmp = new Bitmap(ImageWidth, ImageHeight, ImageWidth * 6, System.Drawing.Imaging.PixelFormat.Format48bppRgb, intPtr);
//bufferGCHandle.Free();
*/
Bitmap bmp = new Bitmap(ImageWidth, ImageHeight, System.Drawing.Imaging.PixelFormat.Format48bppRgb);
Bitmap bmp = new Bitmap(ImageWidth, ImageHeight, System.Drawing.Imaging.PixelFormat.Format48bppRgb);
System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, ImageWidth, ImageHeight), System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat);
Marshal.Copy(buff, 0, bmpData.Scan0, bmpData.Stride * ImageHeight);
bmp.UnlockBits(bmpData);
return bmp;
}
public (int windowWidth, int windowCenter) CalculateWindowLevel(byte[] imageData)
......@@ -260,7 +260,6 @@ namespace Asa
return (windowWidth, windowCenter);
}
volatile bool buffgetted = false;
ManualResetEventSlim buffgettedEvt = new ManualResetEventSlim(false);
int getpiccount = 0;
public bool GetImage(int _MaxFrameCount = 3, int MaxDelay = 5000)
......@@ -281,14 +280,14 @@ namespace Asa
//}
WriteLog("GetImage start========================");
getpiccount = _MaxFrameCount;
buffgetted = false;
buffgettedEvt.Reset();
int ret = HBI_FPD_DLL.HBI_SinglePrepare(HBI_FPD_DLL._handel); //5
if (ret != 0) WriteLog("HBI_SinglePrepare:" + GetHbiError(ret));
else WriteLog("0x02 prepare成功");
buffgettedEvt.Wait(TimeSpan.FromMilliseconds(MaxDelay));
var isintime = buffgettedEvt.Wait(TimeSpan.FromMilliseconds(MaxDelay));
WriteLog("GetImage end =" + isintime + "=======================");
/*
if (buffer != null)
{
......@@ -354,7 +353,7 @@ namespace Asa
}
WriteLog(string.Format("Set LiveAcquisition time.:[{0}]\n", time));
_ret = HBI_FPD_DLL.HBI_SetLiveAcquisitionTime(HBI_FPD_DLL._handel, time);
_ret = HBI_FPD_DLL.HBI_SetLiveAcquisitionTime(HBI_FPD_DLL._handel, time);
if (0 != _ret)
{
LOG.Error("HBI_SetLiveAcquisitionTime failed!");
......@@ -549,9 +548,12 @@ namespace Asa
// 当前反馈固件参数,转化为结构体 add by mhyang 20220402
imagedata = (ImageData)Marshal.PtrToStructure(ptrParam1, typeof(ImageData));
#if !savebmp8 // 正常按照16bit图像显示,add by mhyang 20220615
if (SaveImage() == 0) // 保存
if (SaveImage() == 1) // 保存
{
buffgettedEvt.Set();
}
else
{
buffgetted = true;
buffgettedEvt.Set();
}
#else // 按照8bit图像显示,add by mhyang 20221104
......@@ -771,9 +773,9 @@ namespace Asa
}
// 校正使能状态
//if (m_pLastRegCfg.m_ImgCaliCfg.m_byOffsetCorrection >= 0x00 && m_pLastRegCfg.m_ImgCaliCfg.m_byOffsetCorrection <= 0x03)
//cboxOffsetEnable.SelectedIndex = m_pLastRegCfg.m_ImgCaliCfg.m_byOffsetCorrection;
//cboxOffsetEnable.SelectedIndex = m_pLastRegCfg.m_ImgCaliCfg.m_byOffsetCorrection;
//else
//cboxOffsetEnable.SelectedIndex = 0;
//cboxOffsetEnable.SelectedIndex = 0;
WriteLog(string.Format("\tOffset correction disenable.0x{0:X000}\n", (int)(m_pLastRegCfg.m_ImgCaliCfg.m_byOffsetCorrection)));
//
//if (m_pLastRegCfg.m_ImgCaliCfg.m_byGainCorrection >= 0x00 && m_pLastRegCfg.m_ImgCaliCfg.m_byGainCorrection <= 0x02)
......@@ -996,7 +998,8 @@ namespace Asa
//
return 1;
}
catch (Exception ex) {
catch (Exception ex)
{
WriteLog($"SaveImage fail:{ex}\n");
}
return 0;
......@@ -1044,13 +1047,14 @@ namespace Asa
tmode = EnumIMAGE_ACQ_CMD.GAIN_TEMPLATE_TYPE;
btnSetCorrectEnable(false);
}
int ret = HBI_FPD_DLL.HBI_GenerateTemplate(HBI_FPD_DLL._handel, tmode);
WriteLog($"ret:{ret},tmode:{tmode}");
if (ret != 0)
return false;
if (mode == 2) {
if (mode == 2)
{
downloadStatus = 0; //下载前置0
// 第二步:注册回调函数
ret = HBI_FPD_DLL.HBI_RegProgressCallBack(HBI_FPD_DLL._handel, DownloadCallBack, IntPtr.Zero);
......@@ -1070,12 +1074,14 @@ namespace Asa
WriteLog("HBI_DownloadTemplateByType:gain template failed!ret:[{0}]:" + GetHbiError(ret));
return false;
}
for (int i=0;i<30;i++){
for (int i = 0; i < 30; i++)
{
if (downloadStatus == 0)
{
Task.Delay(1000).Wait();
}
else {
else
{
if (downloadStatus == 1)
{
WriteLog("模版下载成功");
......@@ -1089,9 +1095,9 @@ namespace Asa
return false;
}
}
}
}
//Task a = Task.Delay(160*1000);
......@@ -1109,7 +1115,7 @@ namespace Asa
// WriteLog($"{tmode}: time out");
// return false;
//}
return true;
}
// dwnload template callcallback function
......@@ -1209,7 +1215,8 @@ namespace Asa
return 1;
}
void WriteLog(string log) {
void WriteLog(string log)
{
LOG.Info(log);
}
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!