Commit e6c70111 authored by 潘栩锋's avatar 潘栩锋 🚴

添加 TimeOutEvent 事件

parent d67c4e95
...@@ -43,9 +43,9 @@ namespace GeneralGommunication ...@@ -43,9 +43,9 @@ namespace GeneralGommunication
/// <summary> /// <summary>
/// 有数据需要发送 /// 有数据需要发送
/// </summary> /// </summary>
public event SendDataEventHander SendMsgEvent; public event SendDataEventHandler SendMsgEvent;
public event TimeOutEventHandler TimeOutEvent;
...@@ -125,6 +125,8 @@ namespace GeneralGommunication ...@@ -125,6 +125,8 @@ namespace GeneralGommunication
{ {
//已经重试了3次,放弃 //已经重试了3次,放弃
ResetMsg(); ResetMsg();
//连接断开
TimeOutEvent?.Invoke(this);
return; return;
} }
else else
...@@ -140,6 +142,9 @@ namespace GeneralGommunication ...@@ -140,6 +142,9 @@ namespace GeneralGommunication
//IsConnected = true; //IsConnected = true;
csm.IncRec(recBuf.Count()); csm.IncRec(recBuf.Count());
List<byte[]> packs = new List<byte[]>();
lock (currPack)
{
for (int i = 0; i < recBuf.Count(); i++) for (int i = 0; i < recBuf.Count(); i++)
{ {
if (recBuf[i] == 0x7e) if (recBuf[i] == 0x7e)
...@@ -149,16 +154,18 @@ namespace GeneralGommunication ...@@ -149,16 +154,18 @@ namespace GeneralGommunication
if (currPack.Count > 0) if (currPack.Count > 0)
{ {
var pack = currPack.ToArray(); var pack = currPack.ToArray();
ParsePack(pack); packs.Add(pack);
currPack.Clear(); currPack.Clear();
csm.IncPack(1); csm.IncPack(1);
} }
} }
currPack.Add(recBuf[i]); currPack.Add(recBuf[i]);
} }
}
for (int i = 0; i < packs.Count(); i++) {
//OnPoll_TimeOut(); ParsePack(packs[i]);
}
} }
......
...@@ -28,7 +28,7 @@ namespace GeneralGommunication ...@@ -28,7 +28,7 @@ namespace GeneralGommunication
/// <summary> /// <summary>
/// 有数据需要发送 /// 有数据需要发送
/// </summary> /// </summary>
event SendDataEventHander SendMsgEvent; event SendDataEventHandler SendMsgEvent;
#region 模块运行接口 #region 模块运行接口
......
...@@ -21,7 +21,7 @@ namespace GeneralGommunication ...@@ -21,7 +21,7 @@ namespace GeneralGommunication
/// <summary> /// <summary>
/// 有数据需要发送 /// 有数据需要发送
/// </summary> /// </summary>
event SendDataEventHander SendMsgEvent; event SendDataEventHandler SendMsgEvent;
/// <summary> /// <summary>
/// 设备连接状态改变 /// 设备连接状态改变
......
...@@ -37,7 +37,7 @@ namespace GeneralGommunication ...@@ -37,7 +37,7 @@ namespace GeneralGommunication
/// <summary> /// <summary>
/// 有数据需要发送 /// 有数据需要发送
/// </summary> /// </summary>
public event SendDataEventHander SendMsgEvent; public event SendDataEventHandler SendMsgEvent;
public event DeviceConnectEventHander DeviceConnectEvent; public event DeviceConnectEventHander DeviceConnectEvent;
......
...@@ -36,7 +36,7 @@ namespace GeneralGommunication ...@@ -36,7 +36,7 @@ namespace GeneralGommunication
/// <summary> /// <summary>
/// 有数据需要发送 /// 有数据需要发送
/// </summary> /// </summary>
public event SendDataEventHander SendMsgEvent; public event SendDataEventHandler SendMsgEvent;
/// <summary> /// <summary>
/// 对于全部 有返回的函数调用,都使用Dispatcher,使线程同步 /// 对于全部 有返回的函数调用,都使用Dispatcher,使线程同步
......
...@@ -101,5 +101,8 @@ namespace GeneralGommunication ...@@ -101,5 +101,8 @@ namespace GeneralGommunication
public string errMsg; public string errMsg;
} }
public delegate void SendDataEventHander(object sender, byte[] data); public delegate void SendDataEventHandler(object sender, byte[] data);
public delegate void TimeOutEventHandler(object sender);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment