Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
RC1250-ACPackingStore
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 50093b71
由
LN
编写于
2020-03-11 21:14:52 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
扫码修改
1 个父辈
60879914
显示空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
370 行增加
和
84 行删除
dll/CodeLibrary.dll
source/ACPackingStore/FrmStore.cs
source/ACPackingStore/记录.txt
source/Common/util/HttpHelper.cs
source/DeviceLibrary/device/halcon/CodeManager - back.cs
source/DeviceLibrary/device/halcon/CodeManager.cs
dll/CodeLibrary.dll
查看文件 @
50093b7
此文件类型无法预览
source/ACPackingStore/FrmStore.cs
查看文件 @
50093b7
using
log4net
;
using
CodeLibrary
;
using
log4net
;
using
OnlineStore.Common
;
using
OnlineStore.DeviceLibrary
;
using
OnlineStore.LoadCSVLibrary
;
...
...
@@ -200,7 +201,10 @@ namespace OnlineStore.ACPackingStore
IOManager
.
instance
.
CloseAllConnection
();
HumitureController
.
CloseAllPort
();
ACServerManager
.
CloseAllPort
();
if
(
Camera
.
_cam
!=
null
)
{
Camera
.
_cam
.
CloseAll
();
}
//this.Close();
System
.
Environment
.
Exit
(
System
.
Environment
.
ExitCode
);
}
...
...
@@ -457,6 +461,10 @@ namespace OnlineStore.ACPackingStore
private
void
二维码学习
ToolStripMenuItem_Click
(
object
sender
,
EventArgs
e
)
{
if
(
Camera
.
_cam
!=
null
)
{
Camera
.
_cam
.
CloseAll
();
}
CodeLibrary
.
FrmCodeDecode
frm
=
new
CodeLibrary
.
FrmCodeDecode
();
frm
.
ShowDialog
();
}
...
...
source/ACPackingStore/记录.txt
查看文件 @
50093b7
...
...
@@ -93,9 +93,11 @@ shelfLoc问题修改。
扫码问题优化。
出库未结束时,去掉:检测到料架自动入库功能。
20200310
出库mark参数修改
20200311
扫码修改
...
...
source/Common/util/HttpHelper.cs
查看文件 @
50093b7
...
...
@@ -114,8 +114,6 @@ namespace OnlineStore.Common
private
static
int
isLog
=
ConfigAppSettings
.
GetIntValue
(
Setting_Init
.
Server_Log_Open
);
public
static
string
Post
(
string
url
,
string
paramData
,
Encoding
encoding
)
{
//如果Op=0或者Op=5,先拼Ip,不通不发送
if
(
PingURLIP
(
url
,
100
).
Equals
(
false
))
{
return
null
;
...
...
source/DeviceLibrary/device/halcon/CodeManager - back.cs
0 → 100644
查看文件 @
50093b7
using
CodeLibrary
;
using
OnlineStore.Common
;
using
System
;
using
System.Collections.Generic
;
using
System.Drawing
;
using
System.IO
;
using
System.Linq
;
using
System.Runtime.ExceptionServices
;
using
System.Text
;
using
System.Windows.Forms
;
namespace
OnlineStore.DeviceLibrary
{
public
class
CodeManager
{
public
static
List
<
string
>
codeTypeList
=
new
List
<
string
>();
public
static
List
<
string
>
balserNameList
=
new
List
<
string
>();
public
static
List
<
string
>
hikNameList
=
new
List
<
string
>();
private
static
char
spiltChar
=
'#'
;
/// <summary>
/// 初始化摄像机名称和二维码类型
/// </summary>
public
static
void
LoadConfig
()
{
string
codeStr
=
ConfigAppSettings
.
GetValue
(
Setting_Init
.
CodeType
);
codeTypeList
=
new
List
<
string
>();
HDLogUtil
.
LogName
=
"RollingLogFileAppender"
;
try
{
string
[]
codeArray
=
codeStr
.
Split
(
spiltChar
);
foreach
(
string
str
in
codeArray
)
{
if
(
str
.
Trim
().
Equals
(
""
))
{
continue
;
}
LogUtil
.
info
(
"加载到配置二维码类型:"
+
str
.
Trim
());
codeTypeList
.
Add
(
str
.
Trim
());
}
LoadCamera
(
false
);
CodeLibrary
.
HDCodeLearnHelper
.
LoadConfig
(
""
,
codeStr
);
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
"解析摄像机配置出错:"
+
ex
.
StackTrace
);
}
}
private
static
void
LoadCamera
(
bool
isReLoad
)
{
if
(
isReLoad
)
{
try
{
CodeLibrary
.
HIKCamera
.
Instance
.
Load
();
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
"加载HIK相机出错:"
+
ex
.
ToString
());
}
try
{
CodeLibrary
.
BaslerCamera
.
Instance
.
Load
();
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
"加载Basler相机出错:"
+
ex
.
ToString
());
}
}
string
[]
names
=
CodeLibrary
.
HIKCamera
.
Instance
.
CameraName
;
if
(
names
!=
null
)
{
foreach
(
string
n
in
names
)
{
if
(!
hikNameList
.
Contains
(
n
))
{
hikNameList
.
Add
(
n
);
}
}
// hikNameList.AddRange(names);
foreach
(
string
name
in
hikNameList
)
{
LogUtil
.
info
(
"加载到HIK相机:"
+
name
);
}
}
names
=
CodeLibrary
.
BaslerCamera
.
Instance
.
CameraName
;
if
(
names
!=
null
)
{
foreach
(
string
n
in
names
)
{
if
(!
balserNameList
.
Contains
(
n
))
{
balserNameList
.
Add
(
n
);
}
}
// balserNameList.AddRange(names);
foreach
(
string
name
in
balserNameList
)
{
LogUtil
.
info
(
"加载到Balser相机:"
+
name
);
}
}
}
public
static
void
CloseCamera
()
{
BaslerCamera
.
Instance
.
Close
();
HIKCamera
.
Instance
.
Close
();
}
public
static
Bitmap
GetCamerImage
(
string
cameraName
)
{
Bitmap
bitm
=
null
;
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
;
}
private
static
int
codeCount
=
ConfigAppSettings
.
GetIntValue
(
Setting_Init
.
CodeCount
);
[
HandleProcessCorruptedStateExceptions
]
public
static
List
<
string
>
CameraScan
(
List
<
string
>
cameraList
,
string
deviceName
)
{
if
(
codeCount
<
1
)
{
codeCount
=
1
;
}
List
<
string
>
codeList
=
new
List
<
string
>();
//List<CodeInfo> allCodeList = new List<CodeInfo>();
if
(
cameraList
==
null
||
cameraList
.
Count
<=
0
)
{
return
codeList
;
}
try
{
foreach
(
string
cameraName
in
cameraList
)
{
if
(
cameraName
.
Trim
().
Equals
(
""
))
{
continue
;
}
LogUtil
.
info
(
deviceName
+
" 【"
+
cameraName
+
"】开始打开相机获取图片"
);
using
(
Bitmap
bitmap
=
GetCamerImage
(
cameraName
))
{
if
(
bitmap
==
null
)
{
LogUtil
.
error
(
deviceName
+
" 【"
+
cameraName
+
"】获取图片失败,关闭相机"
);
CloseCamera
();
continue
;
}
LogUtil
.
info
(
deviceName
+
" 【"
+
cameraName
+
"】获取图片完成,开始转换图片,并扫码"
);
System
.
Threading
.
Thread
.
Sleep
(
1
);
//转换托盘大概100-150ms,不打印日志
HalconDotNet
.
HObject
ho_Image
=
HDCodeHelper
.
Bitmap2HObjectBpp24
(
bitmap
);
// LogUtil.info(" 相机【" + cameraName + "】转换图片完成,开始扫码");
List
<
CodeInfo
>
cc
=
new
List
<
CodeInfo
>();
string
r
=
""
;
foreach
(
string
codeType
in
codeTypeList
)
{
//判断是否是一维码
if
(
codeType
.
ToLower
().
Equals
(
"barcode"
))
{
cc
=
HDCodeHelper
.
DecodeBarCode
(
ho_Image
);
}
else
{
cc
=
HDCodeHelper
.
DecodeCode
(
ho_Image
,
codeCount
,
GetCodeParamFilePath
(
codeType
),
codeType
);
}
foreach
(
CodeInfo
c
in
cc
)
{
string
str
=
CodeManager
.
ReplaceCode
(
c
.
CodeStr
);
codeList
.
Add
(
str
);
r
=
r
+
"##"
+
str
;
}
// LogUtil.debug(" 相机【" + cameraName + "】【" + codeType + "】扫码完成:" + r);
}
LogUtil
.
info
(
deviceName
+
" 【"
+
cameraName
+
"】扫码完成:"
+
r
);
ho_Image
.
Dispose
();
bitmap
.
Dispose
();
}
}
}
catch
(
AccessViolationException
e
)
{
LogUtil
.
error
(
deviceName
+
" 扫码出现AccessViolationException异常:"
+
e
.
ToString
());
GC
.
Collect
();
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
deviceName
+
" 扫码出错:"
+
ex
.
ToString
());
}
return
codeList
;
}
public
static
string
GetCodeParamFilePath
(
string
codePath
)
{
string
appPath
=
Application
.
StartupPath
;
string
path
=
appPath
+
ConfigAppSettings
.
GetValue
(
Setting_Init
.
CodeParamPath
);
string
filePath
=
path
+
codePath
+
".dcm"
;
if
(
File
.
Exists
(
filePath
))
{
return
filePath
;
}
else
{
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/device/halcon/CodeManager.cs
查看文件 @
50093b7
...
...
@@ -3,6 +3,7 @@ using OnlineStore.Common;
using
System
;
using
System.Collections.Generic
;
using
System.Drawing
;
using
System.Drawing.Imaging
;
using
System.IO
;
using
System.Linq
;
using
System.Runtime.ExceptionServices
;
...
...
@@ -11,8 +12,6 @@ using System.Windows.Forms;
namespace
OnlineStore.DeviceLibrary
{
public
class
CodeManager
{
public
static
List
<
string
>
codeTypeList
=
new
List
<
string
>();
...
...
@@ -37,7 +36,8 @@ namespace OnlineStore.DeviceLibrary
{
continue
;
}
LogUtil
.
info
(
"加载到配置二维码类型:"
+
str
.
Trim
());
string
file
=
GetCodeParamFilePath
(
str
.
Trim
());
LogUtil
.
info
(
"加载到配置二维码类型:"
+
str
.
Trim
()+
",配置文件:"
+
file
);
codeTypeList
.
Add
(
str
.
Trim
());
}
...
...
@@ -46,31 +46,28 @@ namespace OnlineStore.DeviceLibrary
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
"解析摄像机配置出错:"
+
ex
.
StackTrace
);
LogUtil
.
error
(
"解析摄像机配置出错:"
+
ex
.
ToString
()
);
}
}
private
static
void
LoadCamera
(
bool
isReLoad
)
{
if
(
isReLoad
)
if
(
isReLoad
||
Camera
.
_cam
==
null
)
{
try
{
CodeLibrary
.
HIKCamera
.
Instance
.
Load
();
}
catch
(
Exception
ex
)
if
(
Camera
.
_cam
!=
null
)
{
LogUtil
.
error
(
"加载HIK相机出错:"
+
ex
.
ToString
()
);
Camera
.
_cam
.
CloseAll
(
);
}
try
{
CodeLibrary
.
BaslerCamera
.
Instance
.
Load
();
Camera
.
Type
=
CameraType
.
HIK
;
Camera
.
_cam
.
Load
();
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
"加载
Basler相机出错:"
+
ex
.
ToString
());
LogUtil
.
error
(
"加载
HIK相机出错:"
+
ex
.
ToString
());
}
}
string
[]
names
=
C
odeLibrary
.
HIKCamera
.
Instance
.
Camera
Name
;
string
[]
names
=
C
amera
.
_cam
.
Name
;
if
(
names
!=
null
)
...
...
@@ -88,27 +85,17 @@ namespace OnlineStore.DeviceLibrary
LogUtil
.
info
(
"加载到HIK相机:"
+
name
);
}
}
names
=
CodeLibrary
.
BaslerCamera
.
Instance
.
CameraName
;
if
(
names
!=
null
)
{
foreach
(
string
n
in
names
)
{
if
(!
balserNameList
.
Contains
(
n
))
{
balserNameList
.
Add
(
n
);
}
}
// balserNameList.AddRange(names);
foreach
(
string
name
in
balserNameList
)
public
static
void
CloseCamera
(
string
cameraName
)
{
LogUtil
.
info
(
"加载到Balser相机:"
+
n
ame
);
Camera
.
_cam
.
Close
(
cameraN
ame
);
}
}
}
public
static
void
CloseCamera
()
public
static
void
CloseAllCamera
()
{
BaslerCamera
.
Instance
.
Close
();
HIKCamera
.
Instance
.
Close
();
//BaslerCamera.Instance.Close();
//HIKCamera.Instance.Close();
Camera
.
_cam
.
CloseAll
();
}
public
static
Bitmap
GetCamerImage
(
string
cameraName
)
...
...
@@ -116,63 +103,23 @@ namespace OnlineStore.DeviceLibrary
Bitmap
bitm
=
null
;
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
);
}
}
bitm
=
Camera
.
_cam
.
GrabOneImage
(
cameraName
);
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
"
从相机【"
+
cameraName
+
"】获取图片出错:"
+
ex
.
ToString
());
LogUtil
.
error
(
"
【"
+
cameraName
+
"】获取图片出错:"
+
ex
.
ToString
());
}
return
bitm
;
}
private
static
int
codeCount
=
ConfigAppSettings
.
GetIntValue
(
Setting_Init
.
CodeCount
);
[
HandleProcessCorruptedStateExceptions
]
public
static
List
<
string
>
CameraScan
(
List
<
string
>
cameraList
,
string
deviceName
)
public
static
List
<
string
>
CameraScan
(
List
<
string
>
cameraList
,
string
deviceName
,
bool
isSaveImg
=
false
)
{
if
(
codeCount
<
1
)
{
codeCount
=
1
;
}
List
<
string
>
codeList
=
new
List
<
string
>();
//List<CodeInfo> allCodeList = new List<CodeInfo>();
if
(
cameraList
==
null
||
cameraList
.
Count
<=
0
)
{
return
codeList
;
...
...
@@ -190,15 +137,16 @@ namespace OnlineStore.DeviceLibrary
{
if
(
bitmap
==
null
)
{
LogUtil
.
error
(
deviceName
+
" 【"
+
cameraName
+
"】获取图片失败,关闭相机"
);
CloseCamera
();
LogUtil
.
error
(
deviceName
+
" 【"
+
cameraName
+
"】获取图片失败
["
+
Camera
.
_cam
.
ErrInfo
+
"]
,关闭相机"
);
CloseCamera
(
cameraName
);
continue
;
}
LogUtil
.
info
(
deviceName
+
" 【"
+
cameraName
+
"】获取图片完成,开始转换图片,并扫码"
);
System
.
Threading
.
Thread
.
Sleep
(
1
);
//转换托盘大概100-150ms,不打印日志
HalconDotNet
.
HObject
ho_Image
=
HDCodeHelper
.
Bitmap2HObjectBpp24
(
bitmap
);
Bitmap
bit
=
new
Bitmap
(
bitmap
);
HalconDotNet
.
HObject
ho_Image
=
HDCodeHelper
.
Bitmap2HObjectBpp24
(
bit
);
// LogUtil.info(" 相机【" + cameraName + "】转换图片完成,开始扫码");
List
<
CodeInfo
>
cc
=
new
List
<
CodeInfo
>();
string
r
=
""
;
...
...
@@ -216,13 +164,20 @@ namespace OnlineStore.DeviceLibrary
foreach
(
CodeInfo
c
in
cc
)
{
string
str
=
CodeManager
.
ReplaceCode
(
c
.
CodeStr
);
if
(!
codeList
.
Contains
(
str
))
{
codeList
.
Add
(
str
);
r
=
r
+
"##"
+
str
;
}
}
// LogUtil.debug(" 相机【" + cameraName + "】【" + codeType + "】扫码完成:" + r);
}
if
(
String
.
IsNullOrEmpty
(
r
))
{
SaveImageToFile
(
deviceName
,
cameraName
,
bit
);
}
LogUtil
.
info
(
deviceName
+
" 【"
+
cameraName
+
"】扫码完成:"
+
r
);
bit
.
Dispose
();
ho_Image
.
Dispose
();
bitmap
.
Dispose
();
}
...
...
@@ -240,6 +195,26 @@ namespace OnlineStore.DeviceLibrary
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
)
{
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论