Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
RC30-AutoInOutStore
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit ee922d2c
由
LN
编写于
2020-06-29 09:22:37 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
新扫码方式修改
1 个父辈
e7901fbb
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
153 行增加
和
121 行删除
dll/CodeLibrary.dll
source/DeviceLibrary/DeviceLibrary/halcon/CodeManager.cs
source/DeviceLibrary/acSingleStore/AutomaticBaiting.cs
dll/CodeLibrary.dll
查看文件 @
ee922d2
此文件类型无法预览
source/DeviceLibrary/DeviceLibrary/halcon/CodeManager.cs
查看文件 @
ee922d2
...
@@ -9,6 +9,8 @@ using System.Runtime.ExceptionServices;
...
@@ -9,6 +9,8 @@ using System.Runtime.ExceptionServices;
using
System.Text
;
using
System.Text
;
using
System.Windows.Forms
;
using
System.Windows.Forms
;
using
CodeLibrary
;
using
CodeLibrary
;
using
System.Drawing.Imaging
;
namespace
OnlineStore.DeviceLibrary
namespace
OnlineStore.DeviceLibrary
{
{
public
class
CodeManager
public
class
CodeManager
...
@@ -18,8 +20,7 @@ namespace OnlineStore.DeviceLibrary
...
@@ -18,8 +20,7 @@ namespace OnlineStore.DeviceLibrary
private
static
int
QRCodeCount
=
ConfigAppSettings
.
GetIntValue
(
Setting_Init
.
QRCodeCount
);
private
static
int
QRCodeCount
=
ConfigAppSettings
.
GetIntValue
(
Setting_Init
.
QRCodeCount
);
public
static
List
<
string
>
cameraNameList
=
new
List
<
string
>();
public
static
List
<
string
>
cameraNameList
=
new
List
<
string
>();
public
static
List
<
string
>
codeTypeList
=
new
List
<
string
>();
public
static
List
<
string
>
codeTypeList
=
new
List
<
string
>();
//public static List<string> balserNameList = new List<string>();
public
static
List
<
string
>
balserNameList
=
new
List
<
string
>();
public
static
List
<
string
>
hikNameList
=
new
List
<
string
>();
public
static
List
<
string
>
hikNameList
=
new
List
<
string
>();
private
static
char
spiltChar
=
'#'
;
private
static
char
spiltChar
=
'#'
;
...
@@ -34,7 +35,6 @@ namespace OnlineStore.DeviceLibrary
...
@@ -34,7 +35,6 @@ namespace OnlineStore.DeviceLibrary
}
}
string
nameStr
=
ConfigAppSettings
.
GetValue
(
Setting_Init
.
CameraName
);
string
nameStr
=
ConfigAppSettings
.
GetValue
(
Setting_Init
.
CameraName
);
string
codeStr
=
ConfigAppSettings
.
GetValue
(
Setting_Init
.
CodeType
);
string
codeStr
=
ConfigAppSettings
.
GetValue
(
Setting_Init
.
CodeType
);
cameraNameList
=
new
List
<
string
>();
codeTypeList
=
new
List
<
string
>();
codeTypeList
=
new
List
<
string
>();
HDLogUtil
.
LogName
=
"RollingLogFileAppender"
;
HDLogUtil
.
LogName
=
"RollingLogFileAppender"
;
try
try
...
@@ -56,7 +56,8 @@ namespace OnlineStore.DeviceLibrary
...
@@ -56,7 +56,8 @@ namespace OnlineStore.DeviceLibrary
{
{
continue
;
continue
;
}
}
LogUtil
.
info
(
"加载到配置二维码类型:"
+
str
.
Trim
());
string
file
=
GetCodeParamFilePath
(
str
.
Trim
());
LogUtil
.
info
(
"加载到配置二维码类型:"
+
str
.
Trim
()
+
",配置文件:"
+
file
);
codeTypeList
.
Add
(
str
.
Trim
());
codeTypeList
.
Add
(
str
.
Trim
());
}
}
...
@@ -80,178 +81,165 @@ namespace OnlineStore.DeviceLibrary
...
@@ -80,178 +81,165 @@ namespace OnlineStore.DeviceLibrary
catch
(
Exception
ex
)
catch
(
Exception
ex
)
{
{
LogUtil
.
error
(
"解析摄像机配置出错:"
+
ex
.
StackTrace
);
LogUtil
.
error
(
"解析摄像机配置出错:"
+
ex
.
StackTrace
);
}
}
}
}
private
static
void
LoadCamera
(
bool
isReLoad
)
private
static
void
LoadCamera
(
bool
isReLoad
)
{
{
if
(
isReLoad
)
if
(
isReLoad
||
Camera
.
_cam
==
null
)
{
{
try
try
{
{
CodeLibrary
.
HIKCamera
.
Instance
.
Load
();
if
(
Camera
.
_cam
!=
null
)
{
Camera
.
_cam
.
CloseAll
();
}
Camera
.
Type
=
CameraType
.
HIK
;
Camera
.
_cam
.
Load
();
}
}
catch
(
Exception
ex
)
catch
(
Exception
ex
)
{
{
LogUtil
.
error
(
"加载HIK相机出错:"
+
ex
.
ToString
());
LogUtil
.
error
(
"加载HIK相机出错:"
+
ex
.
ToString
());
}
}
try
{
CodeLibrary
.
BaslerCamera
.
Instance
.
Load
();
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
"加载Basler相机出错:"
+
ex
.
ToString
());
}
}
}
string
[]
names
=
C
odeLibrary
.
HIKCamera
.
Instance
.
Camera
Name
;
string
[]
names
=
C
amera
.
_cam
.
Name
;
if
(
names
!=
null
)
if
(
names
!=
null
)
{
{
hikNameList
.
AddRange
(
names
);
foreach
(
string
n
in
names
)
foreach
(
string
name
in
hikNameList
)
{
{
LogUtil
.
info
(
"加载到HIK相机:"
+
name
);
if
(!
hikNameList
.
Contains
(
n
))
{
hikNameList
.
Add
(
n
);
}
}
}
}
// hikNameList.AddRange(names);
names
=
CodeLibrary
.
BaslerCamera
.
Instance
.
CameraName
;
foreach
(
string
name
in
hikNameList
)
if
(
names
!=
null
)
{
balserNameList
.
AddRange
(
names
);
foreach
(
string
name
in
balserNameList
)
{
{
LogUtil
.
info
(
"加载到
Balser
相机:"
+
name
);
LogUtil
.
info
(
"加载到
HIK
相机:"
+
name
);
}
}
}
}
}
}
public
static
void
CloseCamera
()
public
static
void
CloseCamera
(
string
cameraName
)
{
{
BaslerCamera
.
Instance
.
Close
();
Camera
.
_cam
.
Close
(
cameraName
);
HIKCamera
.
Instance
.
Close
();
}
}
public
static
void
CloseAllCamera
()
public
static
Bitmap
GetCamerImage
(
string
cameraName
)
{
{
Bitmap
bitm
=
null
;
Camera
.
_cam
.
CloseAll
();
try
{
if
(
balserNameList
.
Contains
(
cameraName
))
{
bool
result
=
BaslerCamera
.
Instance
.
Open
(
cameraName
);
// LogUtil.info("打开相机:" + cameraName + "(" + result + ")");
if
(
result
)
{
BaslerCamera
.
Instance
.
GrabOne
();
bitm
=
BaslerCamera
.
Instance
.
Image
;
BaslerCamera
.
Instance
.
Close
();
}
else
{
LogUtil
.
error
(
"相机【"
+
cameraName
+
"】打开失败:"
+
BaslerCamera
.
Instance
.
ErrInfo
);
}
}
else
if
(
hikNameList
.
Contains
(
cameraName
))
{
bool
result
=
HIKCamera
.
Instance
.
Open
(
cameraName
);
// LogUtil.info("打开相机:" + cameraName + "(" + result + ")");
if
(
result
)
{
HIKCamera
.
Instance
.
GrabOne
();
bitm
=
HIKCamera
.
Instance
.
Image
;
HIKCamera
.
Instance
.
Close
();
}
else
{
LogUtil
.
error
(
"相机【"
+
cameraName
+
"】打开失败:"
+
HIKCamera
.
Instance
.
ErrInfo
);
}
}
else
{
LogUtil
.
info
(
"未找到相机【"
+
cameraName
+
"】无法获取图片"
);
//若未加载到相机,需要重新加载相机
if
(
balserNameList
.
Count
<=
0
&&
hikNameList
.
Count
<=
0
)
{
LogUtil
.
error
(
"获取图片时发现未加载到相机,重新加载相机"
);
LoadCamera
(
true
);
}
}
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
"从相机【"
+
cameraName
+
"】获取图片出错:"
+
ex
.
ToString
());
}
return
bitm
;
}
}
[
HandleProcessCorruptedStateExceptions
]
[
HandleProcessCorruptedStateExceptions
]
public
static
List
<
string
>
CameraScan
()
public
static
List
<
string
>
CameraScan
(
)
{
{
int
codeCount
=
1
;
List
<
string
>
codeList
=
new
List
<
string
>();
List
<
string
>
codeList
=
new
List
<
string
>();
if
(
cameraNameList
==
null
||
cameraNameList
.
Count
<=
0
)
{
return
codeList
;
}
try
try
{
{
foreach
(
string
cameraName
in
cameraNameList
)
foreach
(
string
cameraName
in
cameraNameList
)
{
{
using
(
Bitmap
bitmap
=
GetCamerImage
(
cameraName
))
if
(
cameraName
.
Trim
().
Equals
(
""
))
{
continue
;
}
DateTime
startTime
=
DateTime
.
Now
;
LogUtil
.
info
(
" 【"
+
cameraName
+
"】开始取图片"
);
HalconDotNet
.
HObject
ho_Image
=
null
;
try
{
{
if
(
bitmap
==
null
)
ho_Image
=
Camera
.
_cam
.
CaptureOnImage
(
cameraName
);
if
(
ho_Image
==
null
)
{
{
LogUtil
.
error
(
" 摄像机【"
+
cameraName
+
"】获取图片失败
,关闭相机"
);
LogUtil
.
error
(
" 【"
+
cameraName
+
"】取图片失败["
+
Camera
.
_cam
.
ErrInfo
+
"]
,关闭相机"
);
CloseCamera
();
CloseCamera
(
cameraName
);
continue
;
continue
;
}
}
LogUtil
.
info
(
" 【"
+
cameraName
+
"】取图片完成,开始扫码"
);
L
ogUtil
.
debug
(
" 摄像机【"
+
cameraName
+
"】获取图片完成"
);
L
ist
<
CodeInfo
>
cc
=
new
List
<
CodeInfo
>(
);
System
.
Threading
.
Thread
.
Sleep
(
1
)
;
string
r
=
""
;
if
(
DeCodeType
.
Equals
(
0
)
)
foreach
(
string
codeType
in
codeTypeList
)
{
{
HalconDotNet
.
HObject
ho_Image
=
HDCodeHelper
.
Bitmap2HObjectBpp24
(
bitmap
);
//判断是否是一维码
LogUtil
.
debug
(
" 摄像机【"
+
cameraName
+
"】转换图片完成,开始扫码"
);
if
(
codeType
.
ToLower
().
Equals
(
"barcode"
))
foreach
(
string
codeType
in
codeTypeList
)
{
{
List
<
CodeInfo
>
cc
=
new
List
<
CodeInfo
>();
cc
=
HDCodeHelper
.
DecodeBarCode
(
ho_Image
);
//判断是否是一维码
}
if
(
codeType
.
ToLower
().
Equals
(
"barcode"
))
else
{
{
cc
=
HDCodeHelper
.
DecodeBarCode
(
ho_Image
);
cc
=
HDCodeHelper
.
DecodeCode
(
ho_Image
,
codeCount
,
GetCodeParamFilePath
(
codeType
),
codeType
);
}
}
else
foreach
(
CodeInfo
c
in
cc
)
{
{
cc
=
HDCodeHelper
.
DecodeCode
(
ho_Image
,
QRCodeCount
,
GetCodeParamFilePath
(
codeType
),
codeType
);
string
str
=
CodeManager
.
ReplaceCode
(
c
.
CodeStr
);
}
if
(!
codeList
.
Contains
(
str
))
string
r
=
""
;
foreach
(
CodeInfo
c
in
cc
)
{
{
codeList
.
Add
(
c
.
CodeS
tr
);
codeList
.
Add
(
s
tr
);
r
=
r
+
"##"
+
c
.
CodeS
tr
;
r
=
r
+
"##"
+
s
tr
;
}
}
LogUtil
.
debug
(
" ["
+
cameraName
+
"]["
+
codeType
+
"]扫码完成:"
+
r
);
}
}
}
}
else
if
(
String
.
IsNullOrEmpty
(
r
))
{
{
List
<
string
>
result
=
CodeLibrary
.
ZXingCodeHelper
.
DecodeQRCodes
(
bitmap
);
// SaveImageToFile(deviceName, cameraName, bit);
// return result;
}
codeList
.
AddRange
(
result
);
LogUtil
.
info
(
" 【"
+
cameraName
+
"】扫码完成【"
+
FormUtil
.
GetSpanStr
(
DateTime
.
Now
-
startTime
)
+
"】 :"
+
r
);
}
catch
(
AccessViolationException
e
)
{
LogUtil
.
error
(
" 扫码出现AccessViolationException异常,关闭相机【"
+
cameraName
+
"】:"
+
e
.
ToString
());
Camera
.
_cam
.
Close
(
cameraName
);
// GC.Collect();
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
" 扫码出错:"
+
ex
.
ToString
());
}
finally
{
if
(
ho_Image
!=
null
)
{
ho_Image
.
Dispose
();
}
}
}
}
// CloseCamera();
}
}
}
}
catch
(
AccessViolationException
e
)
catch
(
AccessViolationException
e
)
{
{
LogUtil
.
error
(
"
扫码出现AccessViolationException异常:"
+
e
.
ToString
());
LogUtil
.
error
(
"
扫码出现AccessViolationException异常:"
+
e
.
ToString
());
GC
.
Collect
();
//
GC.Collect();
}
}
catch
(
Exception
ex
)
catch
(
Exception
ex
)
{
{
LogUtil
.
error
(
"
扫码出错:"
+
ex
.
ToString
());
LogUtil
.
error
(
"
扫码出错:"
+
ex
.
ToString
());
}
}
return
codeList
;
return
codeList
;
}
}
private
static
void
SaveImageToFile
(
string
deviceName
,
string
cameraName
,
Bitmap
bitmap
)
{
string
date
=
DateTime
.
Now
.
ToString
(
"HH-mm-ss-"
)
+
DateTime
.
Now
.
Millisecond
;
string
dire
=
@"D:\image\" + deviceName.Trim().Replace('_', '-') + @"
\
" + cameraName.Trim().Replace('_', '-').Replace(':', '-') + @"
\
";
string
iamgeName
=
date
+
".bmp"
;
try
{
Bitmap
bit
=
(
Bitmap
)
bitmap
.
Clone
();
if
(
Directory
.
Exists
(
dire
).
Equals
(
false
))
{
Directory
.
CreateDirectory
(
dire
);
}
bit
.
Save
(
dire
+
iamgeName
,
ImageFormat
.
Bmp
);
LogUtil
.
info
(
deviceName
+
" 【"
+
cameraName
+
"】扫码失败,保存图片到【"
+
dire
+
iamgeName
+
"】成功"
);
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
"保存"
+
deviceName
+
" 【"
+
cameraName
+
"】的图片到【"
+
dire
+
iamgeName
+
"】出错"
+
ex
.
ToString
());
}
}
public
static
string
GetCodeParamFilePath
(
string
codePath
)
public
static
string
GetCodeParamFilePath
(
string
codePath
)
{
{
...
@@ -267,5 +255,49 @@ namespace OnlineStore.DeviceLibrary
...
@@ -267,5 +255,49 @@ namespace OnlineStore.DeviceLibrary
return
""
;
return
""
;
}
}
}
}
/// <summary>
/// 处理接收后的二维码
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
public
static
string
ReplaceCode
(
string
message
)
{
message
=
message
.
Trim
();
message
=
message
.
Replace
(
"\r"
,
""
);
message
=
message
.
Replace
(
"\n"
,
""
);
char
a
=
(
char
)
02
;
message
=
message
.
Replace
(
a
.
ToString
(),
""
);
message
=
message
.
Trim
();
System
.
Text
.
ASCIIEncoding
asciiEncoding
=
new
System
.
Text
.
ASCIIEncoding
();
byte
[]
bytes
=
asciiEncoding
.
GetBytes
(
message
);
List
<
byte
>
newBytes
=
new
List
<
byte
>();
foreach
(
byte
by
in
bytes
)
{
int
value
=
(
int
)
by
;
if
(
value
.
Equals
(
24
)
||
value
.
Equals
(
30
)
||
value
.
Equals
(
29
)
||
value
.
Equals
(
4
))
{
continue
;
}
if
(!
value
.
Equals
(
24
))
{
newBytes
.
Add
(
by
);
}
}
message
=
asciiEncoding
.
GetString
(
newBytes
.
ToArray
());
return
message
;
}
public
static
string
ProcessCode
(
List
<
string
>
codeList
)
{
string
code
=
""
;
foreach
(
string
cc
in
codeList
)
{
if
(
string
.
IsNullOrEmpty
(
cc
))
{
continue
;
}
code
+=
cc
+
"##"
;
}
return
ReplaceCode
(
code
);
}
}
}
}
}
source/DeviceLibrary/acSingleStore/AutomaticBaiting.cs
查看文件 @
ee922d2
...
@@ -561,7 +561,7 @@ namespace OnlineStore.DeviceLibrary
...
@@ -561,7 +561,7 @@ namespace OnlineStore.DeviceLibrary
if
(
LastHeight
<
0
)
if
(
LastHeight
<
0
)
{
{
LastHeight
=
StoreManager
.
Config
.
GetDefaultHeight
();
LastHeight
=
StoreManager
.
Config
.
GetDefaultHeight
();
}
}
if
(
LastHeight
<=
8
)
{
LastHeight
=
8
;
}
if
(
LastHeight
<=
8
)
{
LastHeight
=
8
;
}
else
else
{
{
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论