Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
刘韬
/
1069_MIMO_PlUS
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 5d31fcf9
由
张东亮
编写于
2026-01-27 17:24:07 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
添加AOI检测料盘功能
1 个父辈
458e9dcd
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
156 行增加
和
1 行删除
Common/Setting_Init.cs
DLL/AOI.dll
DeviceLibrary/Config/AOI.bmp
DeviceLibrary/Config/AOI.data
DeviceLibrary/DeviceLibrary.csproj
DeviceLibrary/DeviceLibrary/CodeManager.cs
Common/Setting_Init.cs
查看文件 @
5d31fcf
...
...
@@ -116,6 +116,8 @@ namespace OnlineStore.Common
#
region
视觉检查
NG
平台
[
MyConfigComment
(
"是否使用一维码检测料盘在NG平台"
)]
public
static
MyConfig
<
bool
>
CamTestReel_useBarcode
=
false
;
[
MyConfigComment
(
"是否使用AOI检测料盘在NG平台"
)]
public
static
MyConfig
<
bool
>
CamTestReel_useAOI
=
false
;
[
MyConfigComment
(
"NG平台一维码检测料盘:一维码的内容"
)]
public
static
MyConfig
<
string
>
CamTestReel_barcode
=
"RW0000015"
;
...
...
DLL/AOI.dll
0 → 100644
查看文件 @
5d31fcf
此文件类型无法预览
DeviceLibrary/Config/AOI.bmp
0 → 100644
查看文件 @
5d31fcf
此文件类型无法预览
DeviceLibrary/Config/AOI.data
0 → 100644
查看文件 @
5d31fcf
{"methodMap":"{\"L01\":\"{\\\"SamePercent\\\":80.0,\\\"MethodName\\\":\\\"L01\\\",\\\"FullTypeName\\\":\\\"AOI.AoiTemplateMethod\\\",\\\"PathDataStr\\\":\\\"{\\\\\\\"Points\\\\\\\":[{\\\\\\\"IsEmpty\\\\\\\":false,\\\\\\\"X\\\\\\\":317.0,\\\\\\\"Y\\\\\\\":483.666626},{\\\\\\\"IsEmpty\\\\\\\":false,\\\\\\\"X\\\\\\\":553.6666,\\\\\\\"Y\\\\\\\":483.666626},{\\\\\\\"IsEmpty\\\\\\\":false,\\\\\\\"X\\\\\\\":553.6666,\\\\\\\"Y\\\\\\\":593.666565},{\\\\\\\"IsEmpty\\\\\\\":false,\\\\\\\"X\\\\\\\":317.0,\\\\\\\"Y\\\\\\\":593.666565}],\\\\\\\"Types\\\\\\\":\\\\\\\"AAEBgQ==\\\\\\\"}\\\"}\"}"}
\ No newline at end of file
DeviceLibrary/DeviceLibrary.csproj
查看文件 @
5d31fcf
...
...
@@ -35,6 +35,9 @@
<Reference Include="AGVLib">
<HintPath>..\DLL\AGVLib.dll</HintPath>
</Reference>
<Reference Include="AOI">
<HintPath>..\DLL\AOI.dll</HintPath>
</Reference>
<Reference Include="CodeLibrary, Version=1.0.8384.25672, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\DLL\CodeLibrary.dll</HintPath>
...
...
@@ -159,6 +162,9 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="Config\AOI.data">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Config\Config.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
...
...
@@ -176,6 +182,10 @@
<ItemGroup>
<WCFMetadata Include="Connected Services\" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Content Include="Config\AOI.bmp">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
DeviceLibrary/DeviceLibrary/CodeManager.cs
查看文件 @
5d31fcf
...
...
@@ -17,6 +17,7 @@ using System.Runtime.InteropServices;
using
System.Drawing.Drawing2D
;
using
HalconDotNet
;
using
System.Web
;
using
AOI
;
namespace
DeviceLibrary
{
...
...
@@ -267,6 +268,7 @@ namespace DeviceLibrary
DateTime
startTime
=
DateTime
.
Now
;
Bitmap
bmp
=
null
;
bool
usebarcode
=
Setting_Init
.
CamTestReel_useBarcode
;
var
useAOI
=
Setting_Init
.
CamTestReel_useAOI
;
if
(
usebarcode
)
{
try
...
...
@@ -353,6 +355,100 @@ namespace DeviceLibrary
LogUtil
.
info
(
logtxt
);
}
}
else
if
(
useAOI
)
{
try
{
bmp
=
Camera
.
_cam
.
GrabOneImage
(
cameraName
,
PixelType
.
RGB8
);
if
(
bmp
==
null
)
{
if
(
retrytime
>
2
)
return
null
;
retrytime
++;
Camera
.
_cam
.
Close
(
cameraName
);
//LoadCamera(true);
LogUtil
.
info
(
$
"{cameraName} bitmap为空重试第{retrytime}次"
);
Thread
.
Sleep
(
2000
);
goto
retry
;
}
logtxt
+=
$
"【"
+
cameraName
+
"】获取到图像"
+
"\r\n"
;
bool
hasReel
=
false
;
var
projectName
=
"AOI"
;
if
(
Setting_Init
.
CamTestReel_debug
)
srcimg
=
SaveImageToFile
(
"aoiSrc"
,
cameraName
,
bmp
);
AoiProject
project
=
GetAOIProject
(
projectName
);
if
(
project
!=
null
)
{
if
(
bmp
!=
null
)
{
List
<
ResultBean
>
resultBean
=
project
.
CheckAll
(
bmp
,
out
Image
outImage
);
bool
checkResult
=
true
;
string
ngList
=
" AOICheck: "
+
cameraName
+
$
","
+
projectName
+
",结果: "
;
foreach
(
ResultBean
bean
in
resultBean
)
{
ngList
+=
GetShowName
(
bean
)
+
"\r\n"
;
if
(
bean
.
result
.
Equals
(
false
))
{
checkResult
=
false
;
}
}
logtxt
+=
ngList
;
hasReel
=
!
checkResult
;
if
(
Setting_Init
.
CamTestReel_debug
||
(
TestHasRight
.
HasValue
&&
TestHasRight
.
Value
!=
hasReel
))
{
try
{
using
(
Bitmap
b
=
new
Bitmap
(
outImage
))
prcimg
=
SaveImageToFile
(
"aoiResult"
,
cameraName
,
b
);
}
catch
(
Exception
ex
)
{
LogUtil
.
LOGGER
.
Error
(
"AOICheck: 保存结果图失败"
);
}
}
}
else
{
hasReel
=
true
;
LogUtil
.
LOGGER
.
Error
(
"AOICheck: "
+
cameraName
+
"."
+
projectName
+
$
",图片为空"
);
}
}
else
{
LogUtil
.
LOGGER
.
Error
(
"AOICheck: "
+
cameraName
+
"."
+
projectName
+
", 获取AOIProject失败"
);
}
if
(
hasReel
!=
lastHasReel
)
{
lastHasReel
=
hasReel
;
}
else
if
(!
Setting_Init
.
CamTestReel_debug
)
logtxt
=
""
;
TestHasRight
=
null
;
return
hasReel
;
}
catch
(
AccessViolationException
e
)
{
LogUtil
.
error
(
" 扫码出现AccessViolationException异常,关闭相机【"
+
cameraName
+
"】:"
+
e
.
ToString
());
Camera
.
_cam
.
Close
(
cameraName
);
return
null
;
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
" 扫码出错:"
+
ex
.
ToString
());
return
null
;
}
finally
{
if
(
bmp
!=
null
)
bmp
.
Dispose
();
if
(!
string
.
IsNullOrEmpty
(
logtxt
))
LogUtil
.
info
(
logtxt
);
}
}
else
{
try
...
...
@@ -511,6 +607,52 @@ namespace DeviceLibrary
else
return
null
;
}
private
static
string
GetShowName
(
ResultBean
bean
)
{
return
(
bean
.
result
?
"✔ "
:
"✘ "
)
+
bean
.
MethodName
+
$
"({bean.percentValue}%)"
;
}
#
region
AOI
private
static
Dictionary
<
string
,
AoiProject
>
aoiProjectMap
=
new
Dictionary
<
string
,
AoiProject
>();
private
static
AoiProject
GetAOIProject
(
string
projectName
)
{
try
{
string
key
=
$
"{projectName}"
;
if
(!
aoiProjectMap
.
ContainsKey
(
key
))
{
string
path
=
Application
.
StartupPath
+
$
"\\Config\\{projectName}"
;
AoiProject
aoiProject
=
AoiProject
.
Load
(
path
,
out
string
msg
);
if
(
aoiProject
==
null
||
msg
!=
""
)
{
LogUtil
.
LOGGER
.
Error
(
"加载 AoiProject "
+
path
+
" 失败:"
+
msg
);
return
null
;
}
else
{
LogUtil
.
LOGGER
.
Info
(
"加载 AoiProject "
+
path
);
aoiProjectMap
.
Add
(
key
,
aoiProject
);
}
}
return
aoiProjectMap
[
key
];
}
catch
(
Exception
e
)
{
LogUtil
.
LOGGER
.
Error
(
"GetAOIProject 出错: "
+
e
.
ToString
());
}
return
null
;
}
#
endregion
/// <summary>
///
/// </summary>
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论