Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
ACSingleStore
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 635719e6
由
几米阳光
编写于
2019-03-25 15:07:11 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
扫码修改
1 个父辈
4b7db646
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
105 行增加
和
61 行删除
source/DeviceLibrary/KangNaiDe/MasterTcpClient.cs
source/DeviceLibrary/acSingleStore/AC_SA_BoxBean.cs
source/DeviceLibrary/halcon/CodeManager.cs
source/DeviceLibrary/KangNaiDe/MasterTcpClient.cs
查看文件 @
635719e
...
@@ -198,24 +198,23 @@ namespace OnlineStore.DeviceLibrary
...
@@ -198,24 +198,23 @@ namespace OnlineStore.DeviceLibrary
byte
dataLength
=
rdata
[
lengthIndex
];
byte
dataLength
=
rdata
[
lengthIndex
];
int
allLength
=
lengthIndex
+
1
+
dataLength
;
int
allLength
=
lengthIndex
+
1
+
dataLength
;
int
currStartIndex
=
0
;
if
(
rdata
.
Length
>
allLength
)
if
(
rdata
.
Length
>
allLength
)
{
{
//LogUtil.info(clientipe.ToString() + "收到数据(需要分包):" + str);
try
int
currStartIndex
=
0
;
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
{
try
//LogUtil.info(clientipe.ToString() + "收到数据(需要分包):" + str);
{
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
if
(
rdata
.
Length
<
currStartIndex
+
lengthIndex
)
if
(
rdata
.
Length
<
currStartIndex
+
lengthIndex
)
{
{
LogUtil
.
error
(
clientipe
.
ToString
()
+
"收到数据:"
+
str
+
"分包出错 ["
+
currStartIndex
+
"]"
);
LogUtil
.
error
(
clientipe
.
ToString
()
+
"收到数据:"
+
str
+
"分包出错 ["
+
currStartIndex
+
"]"
);
}
}
dataLength
=
rdata
[
currStartIndex
+
lengthIndex
];
dataLength
=
rdata
[
currStartIndex
+
lengthIndex
];
allLength
=
lengthIndex
+
1
+
dataLength
;
allLength
=
lengthIndex
+
1
+
dataLength
;
byte
[]
thisData
=
new
byte
[
allLength
];
byte
[]
thisData
=
new
byte
[
allLength
];
Array
.
Copy
(
rdata
,
currStartIndex
,
thisData
,
0
,
allLength
);
Array
.
Copy
(
rdata
,
currStartIndex
,
thisData
,
0
,
allLength
);
ushort
id
=
BitConverter
.
ToUInt16
(
thisData
,
0
);
ushort
id
=
BitConverter
.
ToUInt16
(
thisData
,
0
);
...
@@ -229,19 +228,18 @@ namespace OnlineStore.DeviceLibrary
...
@@ -229,19 +228,18 @@ namespace OnlineStore.DeviceLibrary
}
}
currStartIndex
=
currStartIndex
+
allLength
;
currStartIndex
=
currStartIndex
+
allLength
;
}
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
clientipe
.
ToString
()
+
"收到数据:"
+
str
+
"分包出错 ["
+
currStartIndex
+
"]:"
+
ex
.
ToString
());
}
}
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
clientipe
.
ToString
()
+
"收到数据:"
+
str
+
"分包出错 ["
+
currStartIndex
+
"]:"
+
ex
.
ToString
());
}
}
}
else
else
{
{
LogUtil
.
debug
(
LOGGER
,
clientipe
.
ToString
()
+
"收到数据(无需分包):"
+
str
);
LogUtil
.
debug
(
LOGGER
,
clientipe
.
ToString
()
+
"收到数据(无需分包):"
+
str
);
ushort
id
=
BitConverter
.
ToUInt16
(
rdata
,
0
);
ushort
id
=
BitConverter
.
ToUInt16
(
rdata
,
0
);
byte
function
=
rdata
[
7
];
byte
function
=
rdata
[
7
];
DataProcess
(
clientipe
.
ToString
(),
id
,
function
,
rdata
);
DataProcess
(
clientipe
.
ToString
(),
id
,
function
,
rdata
);
}
}
}
}
}
}
...
@@ -249,7 +247,10 @@ namespace OnlineStore.DeviceLibrary
...
@@ -249,7 +247,10 @@ namespace OnlineStore.DeviceLibrary
private
void
DataProcess
(
string
clientIp
,
ushort
id
,
byte
function
,
byte
[]
rdata
)
private
void
DataProcess
(
string
clientIp
,
ushort
id
,
byte
function
,
byte
[]
rdata
)
{
{
byte
[]
data
;
byte
[]
data
;
if
(
rdata
.
Length
<=
9
)
{
return
;
}
if
((
function
>=
fctWriteSingleCoil
)
&&
(
function
!=
fctReadWriteMultipleRegister
))
if
((
function
>=
fctWriteSingleCoil
)
&&
(
function
!=
fctReadWriteMultipleRegister
))
{
{
data
=
new
byte
[
2
];
data
=
new
byte
[
2
];
...
...
source/DeviceLibrary/acSingleStore/AC_SA_BoxBean.cs
查看文件 @
635719e
...
@@ -1083,9 +1083,9 @@ namespace OnlineStore.DeviceLibrary
...
@@ -1083,9 +1083,9 @@ namespace OnlineStore.DeviceLibrary
if
(
StoreMove
.
MoveType
.
Equals
(
StoreMoveType
.
None
)
&&
alarmType
.
Equals
(
StoreAlarmType
.
None
))
if
(
StoreMove
.
MoveType
.
Equals
(
StoreMoveType
.
None
)
&&
alarmType
.
Equals
(
StoreAlarmType
.
None
))
{
{
IO_VALUE
checkIO
=
KNDIOValue
(
IO_Type
.
TrayCheck_Door
);
IO_VALUE
checkIO
=
KNDIOValue
(
IO_Type
.
TrayCheck_Door
);
int
height
=
GetHeight
();
//判断料门口是否有料
//判断料门口是否有料
if
((
checkIO
.
Equals
(
IO_VALUE
.
HIGH
))
&&
GetHeight
()
>
0
&&
KNDIOValue
(
IO_Type
.
TrayCheck_Fixture
).
Equals
(
IO_VALUE
.
LOW
))
if
((
checkIO
.
Equals
(
IO_VALUE
.
HIGH
))
&&
height
>
0
&&
KNDIOValue
(
IO_Type
.
TrayCheck_Fixture
).
Equals
(
IO_VALUE
.
LOW
))
{
{
if
(
IsScanCode
)
if
(
IsScanCode
)
{
{
...
@@ -1100,7 +1100,7 @@ namespace OnlineStore.DeviceLibrary
...
@@ -1100,7 +1100,7 @@ namespace OnlineStore.DeviceLibrary
isWaitScan
=
false
;
isWaitScan
=
false
;
IsScanCode
=
true
;
IsScanCode
=
true
;
LogUtil
.
info
(
StoreName
+
"检测到寸料盘,开始扫码"
);
LogUtil
.
info
(
StoreName
+
"检测到
"
+
height
+
"
寸料盘,开始扫码"
);
GetCameraCode
();
GetCameraCode
();
}
}
}
}
...
@@ -1459,7 +1459,7 @@ namespace OnlineStore.DeviceLibrary
...
@@ -1459,7 +1459,7 @@ namespace OnlineStore.DeviceLibrary
#
region
Halcon
扫码枪代码
#
region
Halcon
扫码枪代码
public
bool
IsTestCamera
=
false
;
public
bool
IsTestCamera
=
false
;
private
System
.
Timers
.
Timer
scanTimer
=
null
;
//
private System.Timers.Timer scanTimer = null;
public
void
GetCameraCode
()
public
void
GetCameraCode
()
{
{
if
(
IsTestCamera
&&
IsInScan
())
if
(
IsTestCamera
&&
IsInScan
())
...
@@ -1467,15 +1467,16 @@ namespace OnlineStore.DeviceLibrary
...
@@ -1467,15 +1467,16 @@ namespace OnlineStore.DeviceLibrary
LogUtil
.
info
(
"上次扫码还未执行完毕,请稍后!"
);
LogUtil
.
info
(
"上次扫码还未执行完毕,请稍后!"
);
return
;
return
;
}
}
if
(
scanTimer
==
null
)
//if (scanTimer == null)
{
//{
scanTimer
=
new
System
.
Timers
.
Timer
();
// scanTimer = new System.Timers.Timer();
scanTimer
.
Interval
=
10
;
// scanTimer.Interval = 10;
scanTimer
.
AutoReset
=
false
;
// scanTimer.AutoReset = false;
scanTimer
.
Enabled
=
false
;
// scanTimer.Enabled = false;
scanTimer
.
Elapsed
+=
scanTimer_Elapsed
;
// scanTimer.Elapsed += scanTimer_Elapsed;
}
//}
scanTimer
.
Enabled
=
true
;
//scanTimer.Enabled = true;
Task
.
Factory
.
StartNew
(
delegate
{
scanTimer_Elapsed
(
null
,
null
);
});
}
}
private
string
spiltStr
=
"##"
;
private
string
spiltStr
=
"##"
;
...
@@ -1484,7 +1485,7 @@ namespace OnlineStore.DeviceLibrary
...
@@ -1484,7 +1485,7 @@ namespace OnlineStore.DeviceLibrary
int
height
=
GetHeight
();
int
height
=
GetHeight
();
DateTime
date
=
DateTime
.
Now
;
DateTime
date
=
DateTime
.
Now
;
scanTimer
.
Enabled
=
false
;
//
scanTimer.Enabled = false;
KNDIOMove
(
IO_Type
.
CameraLight_Power
,
IO_VALUE
.
HIGH
);
KNDIOMove
(
IO_Type
.
CameraLight_Power
,
IO_VALUE
.
HIGH
);
string
outMsg
=
""
;
string
outMsg
=
""
;
string
message
=
""
;
string
message
=
""
;
...
...
source/DeviceLibrary/halcon/CodeManager.cs
查看文件 @
635719e
...
@@ -12,9 +12,9 @@ using System.Windows.Forms;
...
@@ -12,9 +12,9 @@ using System.Windows.Forms;
namespace
OnlineStore.DeviceLibrary
namespace
OnlineStore.DeviceLibrary
{
{
public
class
CodeManager
public
class
CodeManager
{
{
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
>();
...
@@ -33,7 +33,7 @@ namespace OnlineStore.DeviceLibrary
...
@@ -33,7 +33,7 @@ namespace OnlineStore.DeviceLibrary
codeTypeList
=
new
List
<
string
>();
codeTypeList
=
new
List
<
string
>();
HDLogUtil
.
LogName
=
"RollingLogFileAppender"
;
HDLogUtil
.
LogName
=
"RollingLogFileAppender"
;
try
try
{
{
string
[]
nameArray
=
nameStr
.
Split
(
spiltChar
);
string
[]
nameArray
=
nameStr
.
Split
(
spiltChar
);
foreach
(
string
str
in
nameArray
)
foreach
(
string
str
in
nameArray
)
{
{
...
@@ -49,8 +49,8 @@ namespace OnlineStore.DeviceLibrary
...
@@ -49,8 +49,8 @@ namespace OnlineStore.DeviceLibrary
string
[]
names
=
CodeLibrary
.
HIKCamera
.
Instance
.
CameraName
;
string
[]
names
=
CodeLibrary
.
HIKCamera
.
Instance
.
CameraName
;
hikNameList
.
AddRange
(
names
);
hikNameList
.
AddRange
(
names
);
foreach
(
string
str
in
names
)
foreach
(
string
str
in
names
)
{
{
LogUtil
.
info
(
"加载到HIK相机:"
+
str
.
Trim
());
LogUtil
.
info
(
"加载到HIK相机:"
+
str
.
Trim
());
}
}
names
=
CodeLibrary
.
BaslerCamera
.
Instance
.
CameraName
;
names
=
CodeLibrary
.
BaslerCamera
.
Instance
.
CameraName
;
...
@@ -60,40 +60,77 @@ namespace OnlineStore.DeviceLibrary
...
@@ -60,40 +60,77 @@ namespace OnlineStore.DeviceLibrary
LogUtil
.
info
(
"加载到Balser相机:"
+
str
.
Trim
());
LogUtil
.
info
(
"加载到Balser相机:"
+
str
.
Trim
());
}
}
CodeLibrary
.
HDCodeLearnHelper
.
LoadConfig
(
nameStr
,
codeStr
);
CodeLibrary
.
HDCodeLearnHelper
.
LoadConfig
(
nameStr
,
codeStr
);
}
}
catch
(
Exception
ex
)
catch
(
Exception
ex
)
{
{
LogUtil
.
error
(
"解析摄像机配置出错:"
+
ex
.
ToString
());
LogUtil
.
error
(
"解析摄像机配置出错:"
+
ex
.
ToString
());
}
}
}
public
static
void
CloseCamera
()
{
BaslerCamera
.
Instance
.
Close
();
HIKCamera
.
Instance
.
Close
();
}
}
public
static
Bitmap
GetCamerImage
(
string
cameraName
)
public
static
Bitmap
GetCamerImage
(
string
cameraName
)
{
{
Bitmap
bitm
=
null
;
Bitmap
bitm
=
null
;
if
(
balserNameList
.
Contains
(
cameraName
))
try
{
BaslerCamera
.
Instance
.
Open
(
cameraName
);
BaslerCamera
.
Instance
.
GrabOne
();
bitm
=
BaslerCamera
.
Instance
.
Image
;
BaslerCamera
.
Instance
.
Close
();
}
else
if
(
hikNameList
.
Contains
(
cameraName
))
{
{
HIKCamera
.
Instance
.
Open
(
cameraName
);
if
(
balserNameList
.
Contains
(
cameraName
))
HIKCamera
.
Instance
.
GrabOne
();
{
bitm
=
HIKCamera
.
Instance
.
Image
;
bool
result
=
BaslerCamera
.
Instance
.
IsOpen
;
HIKCamera
.
Instance
.
Close
();
if
(!
result
)
{
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
.
IsOpen
;
if
(!
result
)
{
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
+
"】无法获取图片"
);
}
}
}
else
catch
(
Exception
ex
)
{
{
LogUtil
.
info
(
"未找到摄像机【"
+
cameraName
+
"】无法获取图片"
);
LogUtil
.
error
(
"从相机【"
+
cameraName
+
"】获取图片出错:"
+
ex
.
ToString
()
);
}
}
return
bitm
;
return
bitm
;
}
}
[
HandleProcessCorruptedStateExceptions
]
[
HandleProcessCorruptedStateExceptions
]
public
static
List
<
string
>
CameraScan
(
)
public
static
List
<
string
>
CameraScan
()
{
{
List
<
string
>
codeList
=
new
List
<
string
>();
List
<
string
>
codeList
=
new
List
<
string
>();
List
<
CodeInfo
>
allCodeList
=
new
List
<
CodeInfo
>();
List
<
CodeInfo
>
allCodeList
=
new
List
<
CodeInfo
>();
...
@@ -102,14 +139,19 @@ namespace OnlineStore.DeviceLibrary
...
@@ -102,14 +139,19 @@ namespace OnlineStore.DeviceLibrary
{
{
foreach
(
string
cameraName
in
cameraNameList
)
foreach
(
string
cameraName
in
cameraNameList
)
{
{
Bitmap
bitmap
=
GetCamerImage
(
cameraName
);
using
(
Bitmap
bitmap
=
GetCamerImage
(
cameraName
))
if
(
bitmap
==
null
)
{
LogUtil
.
info
(
" 摄像机【"
+
cameraName
+
"】获取图片失败"
);
}
else
{
{
if
(
bitmap
==
null
)
{
LogUtil
.
error
(
" 摄像机【"
+
cameraName
+
"】获取图片失败,关闭相机"
);
CloseCamera
();
continue
;
}
LogUtil
.
debug
(
" 摄像机【"
+
cameraName
+
"】获取图片完成"
);
System
.
Threading
.
Thread
.
Sleep
(
1
);
HObject
ho_Image
=
HDCodeHelper
.
Bitmap2HObjectBpp24
(
bitmap
);
HObject
ho_Image
=
HDCodeHelper
.
Bitmap2HObjectBpp24
(
bitmap
);
LogUtil
.
debug
(
" 摄像机【"
+
cameraName
+
"】转换图片完成,开始扫码"
);
List
<
CodeInfo
>
cc
=
new
List
<
CodeInfo
>();
List
<
CodeInfo
>
cc
=
new
List
<
CodeInfo
>();
foreach
(
string
codeType
in
codeTypeList
)
foreach
(
string
codeType
in
codeTypeList
)
{
{
...
@@ -122,10 +164,10 @@ namespace OnlineStore.DeviceLibrary
...
@@ -122,10 +164,10 @@ namespace OnlineStore.DeviceLibrary
{
{
cc
=
HDCodeHelper
.
DecodeCode
(
ho_Image
,
1
,
GetCodeParamFilePath
(
codeType
),
codeType
);
cc
=
HDCodeHelper
.
DecodeCode
(
ho_Image
,
1
,
GetCodeParamFilePath
(
codeType
),
codeType
);
}
}
//LogUtil.info(" 摄像机【" + cameraName + "】【"+ codeType + "】扫码完成");
}
}
allCodeList
.
AddRange
(
cc
);
allCodeList
.
AddRange
(
cc
);
}
}
bitmap
.
Dispose
();
}
}
}
}
catch
(
AccessViolationException
e
)
catch
(
AccessViolationException
e
)
...
@@ -137,13 +179,13 @@ namespace OnlineStore.DeviceLibrary
...
@@ -137,13 +179,13 @@ namespace OnlineStore.DeviceLibrary
{
{
LogUtil
.
error
(
"扫码出错:"
+
ex
.
ToString
());
LogUtil
.
error
(
"扫码出错:"
+
ex
.
ToString
());
}
}
foreach
(
CodeInfo
info
in
allCodeList
)
foreach
(
CodeInfo
info
in
allCodeList
)
{
{
codeList
.
Add
(
info
.
CodeStr
);
codeList
.
Add
(
info
.
CodeStr
);
}
}
return
codeList
;
return
codeList
;
}
}
public
static
string
GetCodeParamFilePath
(
string
codePath
)
public
static
string
GetCodeParamFilePath
(
string
codePath
)
{
{
...
@@ -158,7 +200,7 @@ namespace OnlineStore.DeviceLibrary
...
@@ -158,7 +200,7 @@ namespace OnlineStore.DeviceLibrary
{
{
return
""
;
return
""
;
}
}
}
}
}
}
}
}
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论