Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
ACSingleStore
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 8fb3faf1
由
几米阳光
编写于
2018-11-06 13:43:47 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
serialBean改为Monitor加锁
1 个父辈
3de4897c
全部展开
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
102 行增加
和
84 行删除
source/Common/util/AcSerialBean.cs
source/DeviceLibrary/acSingleStore/AC_SA_BoxBean.cs
source/DeviceLibrary/store/KTK_Store.cs
source/Common/util/AcSerialBean.cs
查看文件 @
8fb3faf
...
...
@@ -226,53 +226,53 @@ namespace OnlineStore.Common
#
endregion
#
region
发送数据
string
类型
public
void
SendData
(
string
data
)
{
//发送数据
if
(
_serialPort
.
IsOpen
)
{
lock
(
lockObj
)
{
_serialPort
.
Write
(
data
);
System
.
Threading
.
Thread
.
Sleep
(
10
);
}
}
}
//
public void SendData(string data)
//
{ //发送数据
//
if (_serialPort.IsOpen)
//
{
//
lock (lockObj)
//
{
//
_serialPort.Write(data);
//
System.Threading.Thread.Sleep(10);
//
}
//
}
//
}
#
endregion
#
region
发送数据
byte
类型
/// <summary>
/// 数据发送
/// </summary>
/// <param name="data">要发送的数据字节</param>
public
void
SendData
(
byte
[]
data
,
int
offset
,
int
count
)
{
///
//
<summary>
///
//
数据发送
///
//
</summary>
///
//
<param name="data">要发送的数据字节</param>
//
public void SendData(byte[] data, int offset, int count)
//
{
string
strSend
=
""
;
for
(
int
i
=
0
;
i
<
data
.
Length
;
i
++)
{
strSend
+=
string
.
Format
(
"{0:X2} "
,
data
[
i
]);
}
LOGGER
.
Debug
(
"【"
+
_serialPort
.
PortName
+
"】发送数据【"
+
strSend
+
"】"
);
lock
(
lockObj
)
{
try
{
if
(
_serialPort
.
IsOpen
)
{
_serialPort
.
DiscardInBuffer
();
//清空接收缓冲区
_serialPort
.
Write
(
data
,
offset
,
count
);
System
.
Threading
.
Thread
.
Sleep
(
10
);
}
}
catch
(
Exception
ex
)
{
_serialPort
.
DiscardOutBuffer
();
LogUtil
.
error
(
LOGGER
,
"SendData ERROR:"
+
ex
.
ToString
(),
21
);
}
}
//
string strSend = "";
//
for (int i = 0; i < data.Length; i++)
//
{
//
strSend += string.Format("{0:X2} ", data[i]);
//
}
//
LOGGER.Debug("【" + _serialPort.PortName + "】发送数据【" + strSend + "】");
//
lock (lockObj)
//
{
//
try
//
{
//
if (_serialPort.IsOpen)
//
{
//
_serialPort.DiscardInBuffer();//清空接收缓冲区
//
_serialPort.Write(data, offset, count);
//
System.Threading.Thread.Sleep(10);
//
}
//
}
//
catch (Exception ex)
//
{
//
_serialPort.DiscardOutBuffer();
//
LogUtil.error(LOGGER, "SendData ERROR:" + ex.ToString(), 21);
//
}
//
}
}
//
}
#
endregion
#
region
发送命令
/// <summary>
...
...
@@ -287,8 +287,10 @@ namespace OnlineStore.Common
isOk
=
false
;
if
(
_serialPort
.
IsOpen
)
{
lock
(
lockObj
)
//lock (lockObj)
if
(
Monitor
.
TryEnter
(
lockObj
,
10
))
{
//Monitor.Enter(lockObj);
try
{
_serialPort
.
DiscardInBuffer
();
//清空接收缓冲区
...
...
@@ -323,6 +325,14 @@ namespace OnlineStore.Common
isOk
=
false
;
LogUtil
.
error
(
LOGGER
,
"SendCommand ERROR:"
+
ex
.
ToString
(),
20
);
}
finally
{
Monitor
.
Exit
(
lockObj
);
}
}
else
{
LogUtil
.
error
(
PortName
+
" 发送数据"
+
ByteToString
(
SendData
)
+
"失败,未得到锁"
);
}
}
...
...
@@ -348,8 +358,9 @@ namespace OnlineStore.Common
if
(
_serialPort
.
IsOpen
)
{
lock
(
lockObj
)
if
(
Monitor
.
TryEnter
(
lockObj
,
10
)
)
{
//Monitor.Enter(lockObj);
try
{
_serialPort
.
DiscardInBuffer
();
//清空接收缓冲区
...
...
@@ -384,9 +395,16 @@ namespace OnlineStore.Common
}
catch
(
Exception
ex
)
{
//throw ex;
LogUtil
.
error
(
PortName
+
" 发送数据"
+
ByteToString
(
SendData
)
+
" 出错:"
+
ex
.
ToString
());
}
finally
{
Monitor
.
Exit
(
lockObj
);
}
}
else
{
LogUtil
.
error
(
PortName
+
" 发送数据"
+
ByteToString
(
SendData
)
+
"失败,未得到锁"
);
}
}
...
...
source/DeviceLibrary/acSingleStore/AC_SA_BoxBean.cs
查看文件 @
8fb3faf
此文件的差异被折叠,
点击展开。
source/DeviceLibrary/store/KTK_Store.cs
查看文件 @
8fb3faf
...
...
@@ -29,8 +29,8 @@ namespace OnlineStore.DeviceLibrary
/// <summary>
/// 伺服运行时间列表,key=轴,key=开始时间,value=结束时间
/// </summary>
public
Dictionary
<
int
,
Dictionary
<
DateTime
,
DateTime
>>
AxisRunTimeMap
=
new
Dictionary
<
int
,
Dictionary
<
DateTime
,
DateTime
>>();
public
Dictionary
<
int
,
DateTime
>
AxisLastStartTime
=
new
Dictionary
<
int
,
DateTime
>();
//
public Dictionary<int, Dictionary<DateTime, DateTime>> AxisRunTimeMap = new Dictionary<int, Dictionary<DateTime, DateTime>>();
//
public Dictionary<int, DateTime> AxisLastStartTime = new Dictionary<int, DateTime>();
/// <summary>
/// 最后一次气压检测变为0的时间
...
...
@@ -93,42 +93,42 @@ namespace OnlineStore.DeviceLibrary
return
new
TimeSpan
(
0
);
}
}
/// <summary>
/// 获取轴已运行时间
/// </summary>
/// <returns></returns>
public
TimeSpan
GetAxisRunTime
(
int
axisNo
)
{
TimeSpan
span
=
new
TimeSpan
(
0
);
try
{
if
(
AxisRunTimeMap
.
ContainsKey
(
axisNo
))
{
Dictionary
<
DateTime
,
DateTime
>
moveMap
=
AxisRunTimeMap
[
axisNo
];
if
(
moveMap
!=
null
&&
moveMap
.
Count
>
0
)
{
foreach
(
DateTime
key
in
moveMap
.
Keys
)
{
span
+=
moveMap
[
key
]
-
key
;
}
}
}
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
LOGGER
,
ex
.
ToString
());
}
return
span
;
}
///
//
<summary>
///
//
获取轴已运行时间
///
//
</summary>
///
//
<returns></returns>
//
public TimeSpan GetAxisRunTime(int axisNo)
//
{
//
TimeSpan span = new TimeSpan(0);
//
try
//
{
//
if (AxisRunTimeMap.ContainsKey(axisNo))
//
{
//
Dictionary<DateTime, DateTime> moveMap = AxisRunTimeMap[axisNo];
//
if (moveMap != null && moveMap.Count > 0)
//
{
//
foreach (DateTime key in moveMap.Keys)
//
{
//
span += moveMap[key] - key;
//
}
//
}
//
}
//
}
//
catch (Exception ex)
//
{
//
LogUtil.error(LOGGER, ex.ToString());
//
}
//
return span;
//
}
protected
void
AddAxisMoveTime
(
ConfigMoveAxis
axis
)
{
int
axisNo
=
axis
.
GetAxisValue
();
if
(
AxisLastStartTime
.
ContainsKey
(
axisNo
))
{
AxisLastStartTime
.
Remove
(
axisNo
);
}
AxisLastStartTime
.
Add
(
axisNo
,
DateTime
.
Now
);
//
int axisNo = axis.GetAxisValue();
//
if (AxisLastStartTime.ContainsKey(axisNo))
//
{
//
AxisLastStartTime.Remove(axisNo);
//
}
//
AxisLastStartTime.Add(axisNo, DateTime.Now);
}
...
...
@@ -233,7 +233,7 @@ namespace OnlineStore.DeviceLibrary
/// <summary>
/// 停止所有运动
/// </summary>
public
abstract
void
StopMove
();
public
abstract
void
StopMove
(
bool
IsCloseAxis
);
/// <summary>
/// 重置处理
...
...
@@ -251,9 +251,9 @@ namespace OnlineStore.DeviceLibrary
{
moveAxis
.
TargetPosition
=
0
;
LogUtil
.
debug
(
LOGGER
,
moveAxis
.
DisplayStr
+
"speed["
+
moveAxis
.
TargetSpeed
+
"]开始原点返回"
);
StoreMove
.
WaitList
.
Add
(
WaitResultInfo
.
WaitAxis
(
moveAxis
,
true
));
AddAxisMoveTime
(
moveAxis
);
ACServerManager
.
HomeMove
(
moveAxis
.
DeviceName
,
(
short
)
moveAxis
.
GetAxisValue
(),
moveAxis
.
HomeHighSpeed
);
StoreMove
.
WaitList
.
Add
(
WaitResultInfo
.
WaitAxis
(
moveAxis
,
true
));
}
/// <summary>
...
...
@@ -261,10 +261,10 @@ namespace OnlineStore.DeviceLibrary
/// </summary>
protected
void
ACAxisMove
(
ConfigMoveAxis
moveAxis
,
int
targetPosition
,
int
targetSpeed
)
{
StoreMove
.
WaitList
.
Add
(
WaitResultInfo
.
WaitAxis
(
moveAxis
,
targetPosition
,
targetSpeed
));
moveAxis
.
TargetPosition
=
targetPosition
;
AddAxisMoveTime
(
moveAxis
);
ACServerManager
.
AbsMove
(
moveAxis
.
DeviceName
,
moveAxis
.
GetAxisValue
(),
targetPosition
,
targetSpeed
);
StoreMove
.
WaitList
.
Add
(
WaitResultInfo
.
WaitAxis
(
moveAxis
,
targetPosition
,
targetSpeed
));
}
/// <summary>
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论