Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
刘韬
/
CarerayImage
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit bf13997a
由
刘韬
编写于
2026-01-06 09:39:04 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
优化haobo_v2图像获取时的等待锁
1 个父辈
0faaa9d2
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
39 行增加
和
28 行删除
CarerayImage/XrayImage.cs
CarerayImage/haobo_v2.cs
CarerayImage/XrayImage.cs
查看文件 @
bf13997
...
@@ -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
...
...
CarerayImage/haobo_v2.cs
查看文件 @
bf13997
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
;
}
}
...
@@ -192,11 +192,11 @@ namespace Asa
...
@@ -192,11 +192,11 @@ namespace Asa
Bitmap bmp = new Bitmap(ImageWidth, ImageHeight, ImageWidth * 6, System.Drawing.Imaging.PixelFormat.Format48bppRgb, intPtr);
Bitmap bmp = new Bitmap(ImageWidth, ImageHeight, ImageWidth * 6, System.Drawing.Imaging.PixelFormat.Format48bppRgb, intPtr);
//bufferGCHandle.Free();
//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
);
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
);
Marshal
.
Copy
(
buff
,
0
,
bmpData
.
Scan0
,
bmpData
.
Stride
*
ImageHeight
);
bmp
.
UnlockBits
(
bmpData
);
bmp
.
UnlockBits
(
bmpData
);
return
bmp
;
return
bmp
;
}
}
public
(
int
windowWidth
,
int
windowCenter
)
CalculateWindowLevel
(
byte
[]
imageData
)
public
(
int
windowWidth
,
int
windowCenter
)
CalculateWindowLevel
(
byte
[]
imageData
)
...
@@ -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)
{
{
...
@@ -354,7 +353,7 @@ namespace Asa
...
@@ -354,7 +353,7 @@ namespace Asa
}
}
WriteLog
(
string
.
Format
(
"Set LiveAcquisition time.:[{0}]\n"
,
time
));
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
)
if
(
0
!=
_ret
)
{
{
LOG
.
Error
(
"HBI_SetLiveAcquisitionTime failed!"
);
LOG
.
Error
(
"HBI_SetLiveAcquisitionTime failed!"
);
...
@@ -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
...
@@ -771,9 +773,9 @@ namespace Asa
...
@@ -771,9 +773,9 @@ namespace Asa
}
}
// 校正使能状态
// 校正使能状态
//if (m_pLastRegCfg.m_ImgCaliCfg.m_byOffsetCorrection >= 0x00 && m_pLastRegCfg.m_ImgCaliCfg.m_byOffsetCorrection <= 0x03)
//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
//else
//cboxOffsetEnable.SelectedIndex = 0;
//cboxOffsetEnable.SelectedIndex = 0;
WriteLog
(
string
.
Format
(
"\tOffset correction disenable.0x{0:X000}\n"
,
(
int
)(
m_pLastRegCfg
.
m_ImgCaliCfg
.
m_byOffsetCorrection
)));
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)
//if (m_pLastRegCfg.m_ImgCaliCfg.m_byGainCorrection >= 0x00 && m_pLastRegCfg.m_ImgCaliCfg.m_byGainCorrection <= 0x02)
...
@@ -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
;
...
@@ -1044,13 +1047,14 @@ namespace Asa
...
@@ -1044,13 +1047,14 @@ namespace Asa
tmode
=
EnumIMAGE_ACQ_CMD
.
GAIN_TEMPLATE_TYPE
;
tmode
=
EnumIMAGE_ACQ_CMD
.
GAIN_TEMPLATE_TYPE
;
btnSetCorrectEnable
(
false
);
btnSetCorrectEnable
(
false
);
}
}
int
ret
=
HBI_FPD_DLL
.
HBI_GenerateTemplate
(
HBI_FPD_DLL
.
_handel
,
tmode
);
int
ret
=
HBI_FPD_DLL
.
HBI_GenerateTemplate
(
HBI_FPD_DLL
.
_handel
,
tmode
);
WriteLog
(
$
"ret:{ret},tmode:{tmode}"
);
WriteLog
(
$
"ret:{ret},tmode:{tmode}"
);
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
(
"模版下载成功"
);
...
@@ -1089,9 +1095,9 @@ namespace Asa
...
@@ -1089,9 +1095,9 @@ namespace Asa
return
false
;
return
false
;
}
}
}
}
}
}
}
}
//Task a = Task.Delay(160*1000);
//Task a = Task.Delay(160*1000);
...
@@ -1109,7 +1115,7 @@ namespace Asa
...
@@ -1109,7 +1115,7 @@ namespace Asa
// WriteLog($"{tmode}: time out");
// WriteLog($"{tmode}: time out");
// return false;
// return false;
//}
//}
return
true
;
return
true
;
}
}
// dwnload template callcallback function
// dwnload template callcallback function
...
@@ -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!
Cancel
请
注册
或
登录
后发表评论