Commit 0faaa9d2 刘韬

优化GetImage 阻塞模式

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