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,25 +142,30 @@ namespace GeneralGommunication ...@@ -140,25 +142,30 @@ namespace GeneralGommunication
//IsConnected = true; //IsConnected = true;
csm.IncRec(recBuf.Count()); csm.IncRec(recBuf.Count());
for (int i = 0; i < recBuf.Count(); i++) List<byte[]> packs = new List<byte[]>();
lock (currPack)
{ {
if (recBuf[i] == 0x7e) for (int i = 0; i < recBuf.Count(); i++)
{ {
//找到头了 if (recBuf[i] == 0x7e)
//结束之前的包
if (currPack.Count > 0)
{ {
var pack = currPack.ToArray(); //找到头了
ParsePack(pack); //结束之前的包
currPack.Clear(); if (currPack.Count > 0)
csm.IncPack(1); {
var pack = currPack.ToArray();
packs.Add(pack);
currPack.Clear();
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