Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
ACSingleStore
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit eaa1096b
由
几米阳光
编写于
2018-12-19 14:43:02 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
伺服通信使用最新代码
1 个父辈
0522a86d
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
68 行增加
和
50 行删除
source/Common/util/AcSerialBean.cs
source/Common/util/LogUtil.cs
source/DeviceLibrary/acSingleStore/AC_SA_BoxBean_Partial.cs
source/Common/util/AcSerialBean.cs
查看文件 @
eaa1096
...
@@ -226,53 +226,53 @@ namespace OnlineStore.Common
...
@@ -226,53 +226,53 @@ namespace OnlineStore.Common
#
endregion
#
endregion
#
region
发送数据
string
类型
#
region
发送数据
string
类型
public
void
SendData
(
string
data
)
//
public void SendData(string data)
{
//发送数据
//
{ //发送数据
if
(
_serialPort
.
IsOpen
)
//
if (_serialPort.IsOpen)
{
//
{
lock
(
lockObj
)
//
lock (lockObj)
{
//
{
_serialPort
.
Write
(
data
);
//
_serialPort.Write(data);
System
.
Threading
.
Thread
.
Sleep
(
10
);
//
System.Threading.Thread.Sleep(10);
}
//
}
}
//
}
}
//
}
#
endregion
#
endregion
#
region
发送数据
byte
类型
#
region
发送数据
byte
类型
/// <summary>
///
//
<summary>
/// 数据发送
///
//
数据发送
/// </summary>
///
//
</summary>
/// <param name="data">要发送的数据字节</param>
///
//
<param name="data">要发送的数据字节</param>
public
void
SendData
(
byte
[]
data
,
int
offset
,
int
count
)
//
public void SendData(byte[] data, int offset, int count)
{
//
{
string
strSend
=
""
;
//
string strSend = "";
for
(
int
i
=
0
;
i
<
data
.
Length
;
i
++)
//
for (int i = 0; i < data.Length; i++)
{
//
{
strSend
+=
string
.
Format
(
"{0:X2} "
,
data
[
i
]);
//
strSend += string.Format("{0:X2} ", data[i]);
}
//
}
LOGGER
.
Debug
(
"【"
+
_serialPort
.
PortName
+
"】发送数据【"
+
strSend
+
"】"
);
//
LOGGER.Debug("【" + _serialPort.PortName + "】发送数据【" + strSend + "】");
lock
(
lockObj
)
//
lock (lockObj)
{
//
{
try
//
try
{
//
{
if
(
_serialPort
.
IsOpen
)
//
if (_serialPort.IsOpen)
{
//
{
_serialPort
.
DiscardInBuffer
();
//清空接收缓冲区
//
_serialPort.DiscardInBuffer();//清空接收缓冲区
_serialPort
.
Write
(
data
,
offset
,
count
);
//
_serialPort.Write(data, offset, count);
System
.
Threading
.
Thread
.
Sleep
(
10
);
//
System.Threading.Thread.Sleep(10);
}
//
}
}
//
}
catch
(
Exception
ex
)
//
catch (Exception ex)
{
//
{
_serialPort
.
DiscardOutBuffer
();
//
_serialPort.DiscardOutBuffer();
LogUtil
.
error
(
LOGGER
,
"SendData ERROR:"
+
ex
.
ToString
(),
21
);
//
LogUtil.error(LOGGER, "SendData ERROR:" + ex.ToString(), 21);
}
//
}
}
//
}
}
//
}
#
endregion
#
endregion
#
region
发送命令
#
region
发送命令
/// <summary>
/// <summary>
...
@@ -282,13 +282,15 @@ namespace OnlineStore.Common
...
@@ -282,13 +282,15 @@ namespace OnlineStore.Common
/// <param name="ReceiveData">接收数据</param>
/// <param name="ReceiveData">接收数据</param>
/// <param name="Overtime">超时时间</param>
/// <param name="Overtime">超时时间</param>
/// <returns></returns>
/// <returns></returns>
public
int
SendCommand
(
byte
[]
SendData
,
ref
byte
[]
ReceiveData
,
int
Overtime
,
out
bool
isOk
)
public
int
SendCommand
(
byte
[]
SendData
,
ref
byte
[]
ReceiveData
,
int
Overtime
,
out
bool
isOk
)
{
{
isOk
=
false
;
isOk
=
false
;
if
(
_serialPort
.
IsOpen
)
if
(
_serialPort
.
IsOpen
)
{
{
lock
(
lockObj
)
//lock (lockObj)
if
(
Monitor
.
TryEnter
(
lockObj
,
10
))
{
{
//Monitor.Enter(lockObj);
try
try
{
{
_serialPort
.
DiscardInBuffer
();
//清空接收缓冲区
_serialPort
.
DiscardInBuffer
();
//清空接收缓冲区
...
@@ -323,6 +325,14 @@ namespace OnlineStore.Common
...
@@ -323,6 +325,14 @@ namespace OnlineStore.Common
isOk
=
false
;
isOk
=
false
;
LogUtil
.
error
(
LOGGER
,
"SendCommand ERROR:"
+
ex
.
ToString
(),
20
);
LogUtil
.
error
(
LOGGER
,
"SendCommand ERROR:"
+
ex
.
ToString
(),
20
);
}
}
finally
{
Monitor
.
Exit
(
lockObj
);
}
}
else
{
LogUtil
.
error
(
PortName
+
" 发送数据"
+
ByteToString
(
SendData
)
+
"失败,未得到锁"
);
}
}
}
}
...
@@ -342,14 +352,15 @@ namespace OnlineStore.Common
...
@@ -342,14 +352,15 @@ namespace OnlineStore.Common
{
{
if
(
_serialPort
==
null
)
if
(
_serialPort
==
null
)
{
{
LogUtil
.
error
(
PortName
+
" 发送数据"
+
ByteToString
(
SendData
)
+
"失败,_serialPort=null"
);
LogUtil
.
error
(
PortName
+
" 发送数据"
+
ByteToString
(
SendData
)
+
"失败,_serialPort=null"
);
return
-
1
;
return
-
1
;
}
}
if
(
_serialPort
.
IsOpen
)
if
(
_serialPort
.
IsOpen
)
{
{
lock
(
lockObj
)
if
(
Monitor
.
TryEnter
(
lockObj
,
10
)
)
{
{
//Monitor.Enter(lockObj);
try
try
{
{
_serialPort
.
DiscardInBuffer
();
//清空接收缓冲区
_serialPort
.
DiscardInBuffer
();
//清空接收缓冲区
...
@@ -384,9 +395,16 @@ namespace OnlineStore.Common
...
@@ -384,9 +395,16 @@ namespace OnlineStore.Common
}
}
catch
(
Exception
ex
)
catch
(
Exception
ex
)
{
{
LogUtil
.
error
(
PortName
+
" 发送数据"
+
ByteToString
(
SendData
)
+
" 出错:"
+
ex
.
ToString
());
//throw ex;
}
}
finally
{
Monitor
.
Exit
(
lockObj
);
}
}
else
{
LogUtil
.
error
(
PortName
+
" 发送数据"
+
ByteToString
(
SendData
)
+
"失败,未得到锁"
);
}
}
}
}
...
...
source/Common/util/LogUtil.cs
查看文件 @
eaa1096
...
@@ -81,7 +81,7 @@ namespace OnlineStore.Common
...
@@ -81,7 +81,7 @@ namespace OnlineStore.Common
if
(
lastErrorLogTime
.
ContainsKey
(
type
))
if
(
lastErrorLogTime
.
ContainsKey
(
type
))
{
{
TimeSpan
span
=
DateTime
.
Now
-
lastErrorLogTime
[
type
];
TimeSpan
span
=
DateTime
.
Now
-
lastErrorLogTime
[
type
];
if
(
span
.
TotalSeconds
<
5
)
if
(
span
.
TotalSeconds
<
10
)
{
{
return
;
return
;
}
}
...
...
source/DeviceLibrary/acSingleStore/AC_SA_BoxBean_Partial.cs
查看文件 @
eaa1096
...
@@ -200,7 +200,7 @@ namespace OnlineStore.DeviceLibrary
...
@@ -200,7 +200,7 @@ namespace OnlineStore.DeviceLibrary
{
{
WarnMsg
=
StoreName
+
"【"
+
StoreMove
.
MoveType
+
"】【"
+
StoreMove
.
MoveStep
+
"】等待超时 ["
+
NotOkMsg
WarnMsg
=
StoreName
+
"【"
+
StoreMove
.
MoveType
+
"】【"
+
StoreMove
.
MoveStep
+
"】等待超时 ["
+
NotOkMsg
+
"]已等待["
+
Math
.
Round
(
span
.
TotalSeconds
,
1
)
+
"]秒"
;
+
"]已等待["
+
Math
.
Round
(
span
.
TotalSeconds
,
1
)
+
"]秒"
;
LogUtil
.
error
(
LOGGER
,
WarnMsg
);
LogUtil
.
error
(
LOGGER
,
WarnMsg
,
100
);
Alarm
(
StoreAlarmType
.
IoSingleTimeOut
,
""
,
WarnMsg
,
StoreMove
.
MoveType
);
Alarm
(
StoreAlarmType
.
IoSingleTimeOut
,
""
,
WarnMsg
,
StoreMove
.
MoveType
);
}
}
}
}
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论