Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
T
Thick-Common
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
潘栩锋
Thick-Common
Commits
73a08e4b
Commit
73a08e4b
authored
Sep 02, 2023
by
潘栩锋
🚴
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.修复 Dev7E 线程安全优化
2.修复 flyad2021B2,连接断开恢复优化
parent
8593d013
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
142 additions
and
402 deletions
+142
-402
Dev7E.cs
GeneralGommunication/Dev7E.cs
+21
-14
GComm_TcpClient.cs
GeneralGommunication/GComm_TcpClient.cs
+67
-373
IDev7E.cs
GeneralGommunication/IDev7E.cs
+1
-1
IModbusAsciiAsync.cs
GeneralGommunication/IModbusAsciiAsync.cs
+1
-1
ModbusAsciiAsync.cs
GeneralGommunication/ModbusAsciiAsync.cs
+1
-1
ModbusRTUAsync.cs
GeneralGommunication/ModbusRTUAsync.cs
+1
-1
Modbus_Transaction.cs
GeneralGommunication/Modbus_Transaction.cs
+4
-1
FlyAd2021B2.cs
Project.FLY.FlyADBase/FlyAd2021.B2/FlyAd2021B2.cs
+46
-10
No files found.
GeneralGommunication/Dev7E.cs
View file @
73a08e4b
...
...
@@ -43,9 +43,9 @@ namespace GeneralGommunication
/// <summary>
/// 有数据需要发送
/// </summary>
public
event
SendDataEventHander
SendMsgEvent
;
public
event
SendDataEventHandler
SendMsgEvent
;
public
event
TimeOutEventHandler
TimeOutEvent
;
...
...
@@ -125,6 +125,8 @@ namespace GeneralGommunication
{
//已经重试了3次,放弃
ResetMsg
();
//连接断开
TimeOutEvent
?.
Invoke
(
this
);
return
;
}
else
...
...
@@ -140,25 +142,30 @@ namespace GeneralGommunication
//IsConnected = true;
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
(
currPack
.
Count
>
0
)
if
(
recBuf
[
i
]
==
0x7e
)
{
var
pack
=
currPack
.
ToArray
();
ParsePack
(
pack
);
currPack
.
Clear
();
csm
.
IncPack
(
1
);
//找到头了
//结束之前的包
if
(
currPack
.
Count
>
0
)
{
var
pack
=
currPack
.
ToArray
();
packs
.
Add
(
pack
);
currPack
.
Clear
();
csm
.
IncPack
(
1
);
}
}
currPack
.
Add
(
recBuf
[
i
]);
}
currPack
.
Add
(
recBuf
[
i
]);
}
//OnPoll_TimeOut();
for
(
int
i
=
0
;
i
<
packs
.
Count
();
i
++)
{
ParsePack
(
packs
[
i
]);
}
}
...
...
GeneralGommunication/GComm_TcpClient.cs
View file @
73a08e4b
This diff is collapsed.
Click to expand it.
GeneralGommunication/IDev7E.cs
View file @
73a08e4b
...
...
@@ -28,7 +28,7 @@ namespace GeneralGommunication
/// <summary>
/// 有数据需要发送
/// </summary>
event
SendDataEventHander
SendMsgEvent
;
event
SendDataEventHand
l
er
SendMsgEvent
;
#
region
模块运行接口
...
...
GeneralGommunication/IModbusAsciiAsync.cs
View file @
73a08e4b
...
...
@@ -21,7 +21,7 @@ namespace GeneralGommunication
/// <summary>
/// 有数据需要发送
/// </summary>
event
SendDataEventHander
SendMsgEvent
;
event
SendDataEventHand
l
er
SendMsgEvent
;
/// <summary>
/// 设备连接状态改变
...
...
GeneralGommunication/ModbusAsciiAsync.cs
View file @
73a08e4b
...
...
@@ -37,7 +37,7 @@ namespace GeneralGommunication
/// <summary>
/// 有数据需要发送
/// </summary>
public
event
SendDataEventHander
SendMsgEvent
;
public
event
SendDataEventHand
l
er
SendMsgEvent
;
public
event
DeviceConnectEventHander
DeviceConnectEvent
;
...
...
GeneralGommunication/ModbusRTUAsync.cs
View file @
73a08e4b
...
...
@@ -36,7 +36,7 @@ namespace GeneralGommunication
/// <summary>
/// 有数据需要发送
/// </summary>
public
event
SendDataEventHander
SendMsgEvent
;
public
event
SendDataEventHand
l
er
SendMsgEvent
;
/// <summary>
/// 对于全部 有返回的函数调用,都使用Dispatcher,使线程同步
...
...
GeneralGommunication/Modbus_Transaction.cs
View file @
73a08e4b
...
...
@@ -101,5 +101,8 @@ namespace GeneralGommunication
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
);
}
Project.FLY.FlyADBase/FlyAd2021.B2/FlyAd2021B2.cs
View file @
73a08e4b
...
...
@@ -10,6 +10,7 @@ using System;
using
System.Collections.Generic
;
using
System.Collections.ObjectModel
;
using
System.ComponentModel
;
using
System.Diagnostics
;
using
System.IO
;
using
System.Linq
;
...
...
@@ -276,6 +277,10 @@ namespace FlyADBase
IsReadyContext
isReadyContext
=
new
IsReadyContext
();
SysTickContext
sysTickContext
=
new
SysTickContext
();
CalSpeed
calSpeed
=
new
CalSpeed
();
/// <summary>
/// 检查推送周期 10ms 有一个。 1秒内都没收到,应该断开了, 重连
/// </summary>
Stopwatch
stopwatch_pushIntervalCheck
=
new
Stopwatch
();
public
FlyAd2021B2Core
Core
=>
core
;
...
...
@@ -334,6 +339,9 @@ namespace FlyADBase
core
.
PushDataEvent
+=
(
sender
,
e
)
=>
{
//喂狗
stopwatch_pushIntervalCheck
.
Restart
();
//这个线程非主线程, 数据接收完,应该快速返回。
//事件触发,都放在主线程操作。
//要有线程锁!!!!!
...
...
@@ -434,6 +442,34 @@ namespace FlyADBase
}
},
TimeSpan
.
FromSeconds
(
1
));
PollModule
.
Current
.
Poll_Config
(
onPoll_CheckPush
);
}
/// <summary>
/// 推送检查 ,没推送,就是连接断开
/// </summary>
private
void
onPoll_CheckPush
()
{
if
(!
IsConnected
)
{
if
(
stopwatch_pushIntervalCheck
.
IsRunning
)
stopwatch_pushIntervalCheck
.
Stop
();
return
;
}
if
(!
stopwatch_pushIntervalCheck
.
IsRunning
)
{
stopwatch_pushIntervalCheck
.
Restart
();
}
else
{
if
(
stopwatch_pushIntervalCheck
.
ElapsedMilliseconds
>
1000
)
{
//1000ms 都没收到推送,连接断开
ReConnect
();
}
}
}
void
GetRunResult
()
...
...
@@ -608,6 +644,8 @@ namespace FlyADBase
}
void
_core_PushDataEvent
(
PushDataEventArgs
e
)
{
Now
=
sysTickContext
.
ToDateTime
(
e
.
SysTick
);
if
(
e
.
ENC1
!=
null
)
...
...
@@ -649,16 +687,6 @@ namespace FlyADBase
advPushData
(
Now
,
e
.
AD
,
e
.
AD2
);
}
private
void
Core_PushDataEvent
(
object
sender
,
PushDataEventArgs
_e
)
{
//这个线程非主线程, 数据接收完,应该快速返回。
//事件触发,都放在主线程操作。
//要有线程锁!!!!!
lock
(
pushEventArgs
)
{
pushEventArgs
.
Add
(
_e
);
}
}
/// <summary>
/// 连接后初始化
...
...
@@ -826,12 +854,20 @@ namespace FlyADBase
}
comm
.
DataReceived
+=
Comm_DataReceived
;
comm
.
PropertyChanged
+=
Comm_PropertyChanged
;
core
.
TimeOutEvent
+=
Core_TimeOutEvent
;
core
.
ResetMsg
();
}
private
void
Core_TimeOutEvent
(
object
sender
)
{
//回复超时,可能连接断开, 重新连接
ReConnect
();
}
void
disposeComm
()
{
comm
.
DataReceived
-=
Comm_DataReceived
;
comm
.
PropertyChanged
-=
Comm_PropertyChanged
;
core
.
TimeOutEvent
-=
Core_TimeOutEvent
;
core
.
ResetMsg
();
}
private
void
Comm_DataReceived
(
IGeneralComm
sender
,
byte
[]
msg
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment