Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
李娜
/
AutoCountMachine
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 0fd210bf
由
LN
编写于
2020-07-24 15:01:13 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
扫码时如果未找到有效条码,把图片保存到文件
1 个父辈
9d181bed
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
62 行增加
和
27 行删除
RC1266-AutoCountMachine/dll/CodeLibrary.dll
RC1266-AutoCountMachine/source/DeviceLibrary/deviceLibrary/halcon/CodeManager.cs
RC1266-AutoCountMachine/dll/CodeLibrary.dll
查看文件 @
0fd210b
此文件类型无法预览
RC1266-AutoCountMachine/source/DeviceLibrary/deviceLibrary/halcon/CodeManager.cs
查看文件 @
0fd210b
...
@@ -95,11 +95,10 @@ namespace OnlineStore.DeviceLibrary
...
@@ -95,11 +95,10 @@ namespace OnlineStore.DeviceLibrary
{
{
Camera
.
_cam
.
CloseAll
();
Camera
.
_cam
.
CloseAll
();
}
}
private
static
int
ScanCount
=
0
;
private
static
int
ScanCount
=
0
;
private
static
int
codeCount
=
ConfigAppSettings
.
GetIntValue
(
Setting_Init
.
CodeCount
);
private
static
int
codeCount
=
ConfigAppSettings
.
GetIntValue
(
Setting_Init
.
CodeCount
);
[
HandleProcessCorruptedStateExceptions
]
[
HandleProcessCorruptedStateExceptions
]
public
static
List
<
string
>
CameraScan
(
string
deviceName
,
params
string
[]
cameraList
)
public
static
List
<
string
>
CameraScan
(
string
deviceName
,
params
string
[]
cameraList
)
{
{
List
<
string
>
codeList
=
new
List
<
string
>();
List
<
string
>
codeList
=
new
List
<
string
>();
if
(
cameraList
==
null
||
cameraList
.
Length
<=
0
)
if
(
cameraList
==
null
||
cameraList
.
Length
<=
0
)
...
@@ -118,10 +117,10 @@ namespace OnlineStore.DeviceLibrary
...
@@ -118,10 +117,10 @@ namespace OnlineStore.DeviceLibrary
DateTime
startTime
=
DateTime
.
Now
;
DateTime
startTime
=
DateTime
.
Now
;
if
(
deviceName
!=
""
)
if
(
deviceName
!=
""
)
{
{
LogUtil
.
debug
(
deviceName
+
" 【"
+
cameraName
+
"】开始取图片"
);
LogUtil
.
debug
(
deviceName
+
" 【"
+
cameraName
+
"】开始取图片"
);
}
}
HalconDotNet
.
HObject
ho_Image
=
null
;
HalconDotNet
.
HObject
ho_Image
=
null
;
bool
findRightCode
=
false
;
try
try
{
{
ho_Image
=
Camera
.
_cam
.
CaptureOnImage
(
cameraName
);
ho_Image
=
Camera
.
_cam
.
CaptureOnImage
(
cameraName
);
...
@@ -144,7 +143,7 @@ namespace OnlineStore.DeviceLibrary
...
@@ -144,7 +143,7 @@ namespace OnlineStore.DeviceLibrary
}
}
else
else
{
{
cc
=
HDCodeHelper
.
DecodeCode
(
ho_Image
,
code
Count
,
GetCodeParamFilePath
(
codeType
),
codeType
);
cc
=
HDCodeHelper
.
DecodeCode
(
ho_Image
,
code
Type
,
GetCodeParamFilePath
(
codeType
),
codeCount
,
1500
);
}
}
foreach
(
CodeInfo
c
in
cc
)
foreach
(
CodeInfo
c
in
cc
)
{
{
...
@@ -153,17 +152,20 @@ namespace OnlineStore.DeviceLibrary
...
@@ -153,17 +152,20 @@ namespace OnlineStore.DeviceLibrary
{
{
codeList
.
Add
(
str
);
codeList
.
Add
(
str
);
r
=
r
+
"##"
+
str
;
r
=
r
+
"##"
+
str
;
if
(!
findRightCode
)
{
findRightCode
=
HasRightCode
(
str
);
}
}
}
}
}
}
if
(
String
.
IsNullOrEmpty
(
r
))
}
if
(!
findRightCode
)
{
{
// SaveImageToFile(deviceName, cameraName, bit
);
SaveImageToFile
(
deviceName
,
cameraName
,
ho_Image
);
}
}
if
(
deviceName
!=
""
||
r
!=
""
)
if
(
deviceName
!=
""
||
r
!=
""
)
{
{
LogUtil
.
info
(
deviceName
+
" 【"
+
cameraName
+
"】扫码完成【"
+
FormUtil
.
GetSpanStr
(
DateTime
.
Now
-
startTime
)
+
"】"
+
ScanCount
+
" :"
+
r
);
LogUtil
.
info
(
deviceName
+
" 【"
+
cameraName
+
"】扫码完成【"
+
FormUtil
.
GetSpanStr
(
DateTime
.
Now
-
startTime
)
+
"】
["
+
findRightCode
+
"]
"
+
ScanCount
+
" :"
+
r
);
}
}
}
}
catch
(
AccessViolationException
e
)
catch
(
AccessViolationException
e
)
...
@@ -197,10 +199,29 @@ namespace OnlineStore.DeviceLibrary
...
@@ -197,10 +199,29 @@ namespace OnlineStore.DeviceLibrary
}
}
return
codeList
;
return
codeList
;
}
}
private
static
void
SaveImageToFile
(
string
deviceName
,
string
cameraName
,
HalconDotNet
.
HObject
bitmap
)
{
string
date
=
deviceName
.
Trim
().
Replace
(
'_'
,
'-'
)
+
"-"
+
DateTime
.
Now
.
ToString
(
"yyyyMMdd-HHmmss"
)
+
"-"
+
DateTime
.
Now
.
Millisecond
.
ToString
().
PadLeft
(
4
,
'0'
);
string
dire
=
@"D:\image\" + deviceName.Trim().Replace('_', '-') + @"
\
" + cameraName.Trim().Replace('_', '-').Replace(':', '-') + @"
\
";
string
iamgeName
=
date
+
".bmp"
;
try
{
if
(!
Directory
.
Exists
(
dire
))
{
Directory
.
CreateDirectory
(
dire
);
}
bitmap
.
WriteObject
(
dire
+
iamgeName
);
LogUtil
.
info
(
deviceName
+
" 【"
+
cameraName
+
"】扫码失败,保存图片到【"
+
dire
+
iamgeName
+
"】成功"
);
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
"保存"
+
deviceName
+
" 【"
+
cameraName
+
"】的图片到【"
+
dire
+
iamgeName
+
"】出错"
+
ex
.
ToString
());
}
}
private
static
void
SaveImageToFile
(
string
deviceName
,
string
cameraName
,
Bitmap
bitmap
)
private
static
void
SaveImageToFile
(
string
deviceName
,
string
cameraName
,
Bitmap
bitmap
)
{
{
string
date
=
DateTime
.
Now
.
ToString
(
"HH-mm-ss-"
)
+
DateTime
.
Now
.
Millisecond
;
string
date
=
deviceName
.
Trim
().
Replace
(
'_'
,
'-'
)
+
"-"
+
DateTime
.
Now
.
ToString
(
"HH-mm-ss-"
)
+
DateTime
.
Now
.
Millisecond
;
string
dire
=
@"D:\image\" + deviceName.Trim().Replace('_', '-') + @"
\
" + cameraName.Trim().Replace('_', '-').Replace(':', '-') + @"
\
";
string
dire
=
@"D:\image\" + deviceName.Trim().Replace('_', '-') + @"
\
" + cameraName.Trim().Replace('_', '-').Replace(':', '-') + @"
\
";
string
iamgeName
=
date
+
".bmp"
;
string
iamgeName
=
date
+
".bmp"
;
try
try
...
@@ -219,7 +240,30 @@ namespace OnlineStore.DeviceLibrary
...
@@ -219,7 +240,30 @@ namespace OnlineStore.DeviceLibrary
}
}
}
}
public
static
bool
HasRightCode
(
params
string
[]
codes
)
{
//分号分割后长度=4,L,E,B,R
try
{
foreach
(
string
code
in
codes
)
{
string
[]
strarray
=
code
.
Split
(
';'
);
if
(
strarray
.
Length
==
4
)
{
if
(
strarray
[
0
].
StartsWith
(
"L"
)
&&
strarray
[
1
].
StartsWith
(
"E"
)
&&
strarray
[
2
].
StartsWith
(
"B"
))
{
return
true
;
}
}
}
}
catch
(
Exception
ex
)
{
}
return
false
;
}
public
static
string
GetCodeParamFilePath
(
string
codePath
)
public
static
string
GetCodeParamFilePath
(
string
codePath
)
{
{
string
appPath
=
Application
.
StartupPath
;
string
appPath
=
Application
.
StartupPath
;
...
@@ -265,27 +309,18 @@ namespace OnlineStore.DeviceLibrary
...
@@ -265,27 +309,18 @@ namespace OnlineStore.DeviceLibrary
message
=
asciiEncoding
.
GetString
(
newBytes
.
ToArray
());
message
=
asciiEncoding
.
GetString
(
newBytes
.
ToArray
());
return
message
;
return
message
;
}
}
private
static
bool
IsRightCode
(
string
code
)
public
static
string
ProcessCode
(
List
<
string
>
codeList
)
{
//分号分割后长度=4,L,E,B,R
try
{
{
string
[]
strarray
=
code
.
Split
(
';'
)
;
string
code
=
""
;
if
(
strarray
.
Length
==
4
)
foreach
(
string
cc
in
codeList
)
{
{
if
(
strarray
[
0
].
StartsWith
(
"L"
)
&&
if
(
string
.
IsNullOrEmpty
(
cc
))
strarray
[
1
].
StartsWith
(
"E"
)
&&
strarray
[
2
].
StartsWith
(
"B"
)
&&
strarray
[
3
].
StartsWith
(
"R"
))
{
{
return
true
;
continue
;
}
}
}
}
catch
(
Exception
ex
)
code
+=
cc
+
"##"
;
{
}
}
return
false
;
return
ReplaceCode
(
code
)
;
}
}
public
static
string
GetValidCode
(
List
<
string
>
codeList
)
public
static
string
GetValidCode
(
List
<
string
>
codeList
)
{
{
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论