Commit 0faaa9d2 刘韬

优化GetImage 阻塞模式

1 个父辈 79c08d62
...@@ -255,10 +255,11 @@ namespace Asa ...@@ -255,10 +255,11 @@ namespace Asa
errmsg = ""; errmsg = "";
if (NeoX.HasNeox() && type.StartsWith("ID")) if (NeoX.HasNeox() && type.StartsWith("ID"))
{ {
var tf = GetTemplateFile(path); var tf = GetTemplateFile(path,out string errmsg2);
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;
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;
...@@ -276,10 +277,11 @@ namespace Asa ...@@ -276,10 +277,11 @@ namespace Asa
eyemImageFree(ref eyem); eyemImageFree(ref eyem);
return n; return n;
} }
public static string GetTemplateFile(string path) public static string GetTemplateFile(string path, out string debugstr)
{ {
try try
{ {
debugstr = "";
// 提取文件名中等于号前面的部分 // 提取文件名中等于号前面的部分
string fileName = Path.GetFileNameWithoutExtension(path); string fileName = Path.GetFileNameWithoutExtension(path);
var splitchar = ConfigHelper.Config.Get("PN_Split_Char", "-"); var splitchar = ConfigHelper.Config.Get("PN_Split_Char", "-");
...@@ -311,13 +313,15 @@ namespace Asa ...@@ -311,13 +313,15 @@ namespace Asa
} }
else else
{ {
return ""; // 文件不存在,返回空 debugstr = "not Exists:" + fullPath; // 文件不存在,返回空
return "";
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
// 处理异常,如路径无法访问、文件名无效等 // 处理异常,如路径无法访问、文件名无效等
Console.WriteLine($"Error: {ex}"); Console.WriteLine($"Error: {ex}");
debugstr = "Error:" + ex.ToString();
return ""; return "";
} }
} }
...@@ -379,7 +383,7 @@ namespace Asa ...@@ -379,7 +383,7 @@ namespace Asa
try try
{ {
var type1 = ccdata[ck]; var type1 = ccdata[ck];
var tf = GetTemplateFile(path); var tf = GetTemplateFile(path, out _);
if (!string.IsNullOrEmpty(tf)) if (!string.IsNullOrEmpty(tf))
type1 = "ID_TYPE_T"; type1 = "ID_TYPE_T";
NeoX.AlgoC(path, tf, ShrinkOffset, Corner + 1, type1, out int c, out Bitmap bitmap, out _); NeoX.AlgoC(path, tf, ShrinkOffset, Corner + 1, type1, out int c, out Bitmap bitmap, out _);
......
...@@ -260,12 +260,11 @@ namespace Asa ...@@ -260,12 +260,11 @@ namespace Asa
return (windowWidth, windowCenter); return (windowWidth, windowCenter);
} }
CancellationTokenSource WaitstopToken = new CancellationTokenSource();
volatile bool buffgetted = false; volatile bool buffgetted = 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)
{ {
WaitstopToken = new CancellationTokenSource();
buffer = null; buffer = null;
//FPD_AQC_MODE stMode = new FPD_AQC_MODE(); //FPD_AQC_MODE stMode = new FPD_AQC_MODE();
...@@ -283,25 +282,13 @@ namespace Asa ...@@ -283,25 +282,13 @@ namespace Asa
WriteLog("GetImage start========================"); WriteLog("GetImage start========================");
getpiccount = _MaxFrameCount; getpiccount = _MaxFrameCount;
buffgetted = false; buffgetted = false;
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));
Task a = Task.Delay(MaxDelay);
Task b = Task.Run(()=> {
while (true)
{
Thread.Sleep(100);
if (buffgetted)
break;
}
});
Task.WaitAny(a, b);
Thread.Sleep(500);
/* /*
if (buffer != null) if (buffer != null)
{ {
...@@ -565,7 +552,7 @@ namespace Asa ...@@ -565,7 +552,7 @@ namespace Asa
if (SaveImage() == 0) // 保存 if (SaveImage() == 0) // 保存
{ {
buffgetted = true; buffgetted = true;
WaitstopToken.Cancel(false); buffgettedEvt.Set();
} }
#else // 按照8bit图像显示,add by mhyang 20221104 #else // 按照8bit图像显示,add by mhyang 20221104
//int length = imagedata.datalen; //int length = imagedata.datalen;
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!