Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
G
GC_Branch
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
周磊
GC_Branch
Commits
eb024034
Commit
eb024034
authored
Sep 07, 2018
by
wangjunqiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加线程监控
parent
634de4fb
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
1273 additions
and
215 deletions
+1273
-215
AppInit.cs
GcDevicePc/AppInit.cs
+10
-0
MoudbusOperation.cs
GcDevicePc/Common/MoudbusOperation.cs
+600
-0
ValveTab.designer.cs
GcDevicePc/ConfigMethod/ValveTab.designer.cs
+128
-197
DataState.cs
GcDevicePc/DataState.cs
+7
-10
GcDevicePc.csproj
GcDevicePc/GcDevicePc.csproj
+5
-0
MDIBase.cs
GcDevicePc/MDIBase.cs
+8
-6
ChannelDataTh.cs
GcDevicePc/ProThread/ChannelDataTh.cs
+107
-0
DisplayDataTh.cs
GcDevicePc/ProThread/DisplayDataTh.cs
+114
-0
HmiStatueTh.cs
GcDevicePc/ProThread/HmiStatueTh.cs
+108
-0
ThreadMonitor.cs
GcDevicePc/ProThread/ThreadMonitor.cs
+180
-0
StartForm.cs
GcDevicePc/StartForm.cs
+2
-0
globaldata.cs
GcDevicePc/globaldata.cs
+4
-2
No files found.
GcDevicePc/AppInit.cs
View file @
eb024034
...
...
@@ -316,5 +316,15 @@ namespace GcDevicePc
}
}
public
void
StartDataThread
()
{
if
(!
String
.
IsNullOrEmpty
(
globaldata
.
connection_ip
))
{
MoudbusOperation
.
GetInstance
().
SetModbusIP
(
globaldata
.
connection_ip
);
ThreadMonitor
.
GetInstance
().
StartALLCommunication
();
ThreadMonitor
.
GetInstance
().
MonitorThStart
();
}
}
}
}
GcDevicePc/Common/MoudbusOperation.cs
0 → 100644
View file @
eb024034
This diff is collapsed.
Click to expand it.
GcDevicePc/ConfigMethod/ValveTab.designer.cs
View file @
eb024034
This diff is collapsed.
Click to expand it.
GcDevicePc/DataState.cs
View file @
eb024034
...
...
@@ -19,8 +19,7 @@ namespace GcDevicePc
public
Thread
updateth
;
// GcDataReq m_data;
GcDataTh
mymodbus
;
// GcDataTh mymodbus;
public
DataState
()
{
...
...
@@ -34,8 +33,8 @@ namespace GcDevicePc
{
try
{
if
(
mymodbus
!=
null
)
mymodbus
.
ShowDataStop
();
//
if (mymodbus != null)
//
mymodbus.ShowDataStop();
}
catch
(
Exception
e
)
{
...
...
@@ -48,8 +47,8 @@ namespace GcDevicePc
{
try
{
if
(
mymodbus
!=
null
)
mymodbus
.
ShowDataStop
();
//
if (mymodbus != null)
//
mymodbus.ShowDataStop();
}
catch
(
Exception
e
)
{
...
...
@@ -67,11 +66,9 @@ namespace GcDevicePc
globaldata
.
m_profileMethod
.
GetDevState
();
if
(!
String
.
IsNullOrEmpty
(
globaldata
.
connection_ip
))
{
//m_data = new GcDataReq(globaldata.connection_ip, globaldata.datamodbusport);
//m_data.Start();
mymodbus
=
new
GcDataTh
(
globaldata
.
connection_ip
,
globaldata
.
datamodbusport
);
mymodbus
.
ShowDataStart
();
//
mymodbus = new GcDataTh(globaldata.connection_ip, globaldata.datamodbusport);
//
mymodbus.ShowDataStart();
System
.
Windows
.
Forms
.
Timer
T
=
new
System
.
Windows
.
Forms
.
Timer
();
T
.
Interval
=
100
;
...
...
GcDevicePc/GcDevicePc.csproj
View file @
eb024034
...
...
@@ -203,6 +203,7 @@
<Compile
Include=
"Common\FileHelper.cs"
/>
<Compile
Include=
"Common\GCModbusSlave485.cs"
/>
<Compile
Include=
"Common\Log.cs"
/>
<Compile
Include=
"Common\MoudbusOperation.cs"
/>
<Compile
Include=
"Common\RunTableHelper.cs"
/>
<Compile
Include=
"Common\SendDataToHW.cs"
/>
<Compile
Include=
"ConfigDlg\ChromeDlg.cs"
>
...
...
@@ -480,12 +481,16 @@
<Compile
Include=
"Program.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"ProThread\ChannelDataSave.cs"
/>
<Compile
Include=
"ProThread\ChannelDataTh.cs"
/>
<Compile
Include=
"ProThread\CKvocUpdata.cs"
/>
<Compile
Include=
"ProThread\DataOutput.cs"
/>
<Compile
Include=
"ProThread\DataRcv.cs"
/>
<Compile
Include=
"ProThread\DisplayDataTh.cs"
/>
<Compile
Include=
"ProThread\GcDataTh.cs"
/>
<Compile
Include=
"ProThread\HMIControl.cs"
/>
<Compile
Include=
"ProThread\HMISearch.cs"
/>
<Compile
Include=
"ProThread\HmiStatueTh.cs"
/>
<Compile
Include=
"ProThread\ThreadMonitor.cs"
/>
<Compile
Include=
"QuitForm.cs"
>
<SubType>
Form
</SubType>
</Compile>
...
...
GcDevicePc/MDIBase.cs
View file @
eb024034
...
...
@@ -755,9 +755,9 @@ namespace GcDevicePc
statestr
=
"设备联机"
;
IsStateColor
=
true
;
hmiopt
=
null
;
hmiopt
=
new
HMIControl
(
globaldata
.
connection_ip
,
globaldata
.
datamodbusport
);
mymodbus
=
null
;
mymodbus
=
new
GcDataTh
(
globaldata
.
connection_ip
,
globaldata
.
datamodbusport
);
...
...
@@ -800,8 +800,8 @@ namespace GcDevicePc
// mydatasave.ChannelDataStart();
if
(!
String
.
IsNullOrEmpty
(
globaldata
.
connection_ip
))
{
mymodbus
.
HmiStatueStart
();
mymodbus
.
ChannelDataStart
();
//
mymodbus.HmiStatueStart();
//
mymodbus.ChannelDataStart();
}
dataVOC
.
CKvocUpdataStart
();
...
...
@@ -820,8 +820,10 @@ namespace GcDevicePc
if
(!
String
.
IsNullOrEmpty
(
globaldata
.
connection_ip
))
{
mymodbus
.
HmiStatueStop
();
mymodbus
.
ChannelDataStop
();
// mymodbus.HmiStatueStop();
// mymodbus.ChannelDataStop();
ThreadMonitor
.
GetInstance
().
MonitorThStop
();
ThreadMonitor
.
GetInstance
().
StopALLCommunication
();
}
if
(!
String
.
IsNullOrEmpty
(
globaldata
.
m_pcbuffer
.
gcpcinfo
.
moduleinfo
.
ip
))
...
...
GcDevicePc/ProThread/ChannelDataTh.cs
0 → 100644
View file @
eb024034
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
GcDevicePc.Common
;
namespace
GcDevicePc.ProThread
{
class
ChannelDataTh
{
/// <summary>
/// 单实例对象
/// </summary>
private
static
ChannelDataTh
instance
=
null
;
//静态私有成员变量
/// <summary>
/// 单实例对象锁
/// </summary>
private
static
object
_lock
=
new
object
();
/// <summary>
/// 数据锁
/// </summary>
private
static
object
_datalock
=
new
object
();
#
region
单实例实现
public
static
ChannelDataTh
GetInstance
()
{
if
(
instance
==
null
)
{
lock
(
_lock
)
{
if
(
instance
==
null
)
{
instance
=
new
ChannelDataTh
();
}
}
}
return
instance
;
}
#
endregion
#
region
分析仪数据读取线程
private
Thread
_tGetChannelData
;
//分析仪读取线程
private
ManualResetEvent
channeldata_mre
=
new
ManualResetEvent
(
false
);
//信号控制量
#
endregion
public
void
ChannelDataThStart
()
{
if
(
channeldata_mre
!=
null
)
{
channeldata_mre
.
Reset
();
}
if
(
_tGetChannelData
!=
null
)
{
_tGetChannelData
.
Abort
();
}
_tGetChannelData
=
new
Thread
(
ChannelDataThProc
);
_tGetChannelData
.
Priority
=
ThreadPriority
.
Highest
;
// _tGetAnalyzerData.IsBackground = true;
_tGetChannelData
.
Start
();
}
/// <summary>
/// 判断线程工作状态
/// </summary>
/// <returns></returns>
public
bool
ThreadWorking
()
{
if
(
_tGetChannelData
!=
null
)
{
if
(
_tGetChannelData
.
ThreadState
==
ThreadState
.
Running
||
(
_tGetChannelData
.
ThreadState
&
ThreadState
.
WaitSleepJoin
)
!=
0
)
return
true
;
else
return
false
;
}
return
false
;
}
/// <summary>
/// 线程停止
/// </summary>
public
void
ChannelDataThStop
()
{
channeldata_mre
.
Set
();
}
/// <summary>
/// 线程工作函数
/// </summary>
private
void
ChannelDataThProc
()
{
while
(!
channeldata_mre
.
WaitOne
(
500
))
{
ReadChannelData
();
}
}
private
void
ReadChannelData
()
{
MoudbusOperation
.
GetInstance
().
Get_Channel_Data
();
}
}
}
GcDevicePc/ProThread/DisplayDataTh.cs
0 → 100644
View file @
eb024034
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
GcDevicePc.Common
;
namespace
GcDevicePc.ProThread
{
class
DisplayDataTh
{
/// <summary>
/// 单实例对象
/// </summary>
private
static
DisplayDataTh
instance
=
null
;
//静态私有成员变量
/// <summary>
/// 单实例对象锁
/// </summary>
private
static
object
_lock
=
new
object
();
/// <summary>
/// 数据锁
/// </summary>
private
static
object
_datalock
=
new
object
();
#
region
单实例实现
public
static
DisplayDataTh
GetInstance
()
{
if
(
instance
==
null
)
{
lock
(
_lock
)
{
if
(
instance
==
null
)
{
instance
=
new
DisplayDataTh
();
}
}
}
return
instance
;
}
#
endregion
#
region
分析仪数据读取线程
private
Thread
_tGetDisplayData
;
//分析仪读取线程
private
ManualResetEvent
displaydata_mre
=
new
ManualResetEvent
(
false
);
//信号控制量
#
endregion
public
void
DisplayDataThStart
()
{
if
(
displaydata_mre
!=
null
)
{
displaydata_mre
.
Reset
();
}
if
(
_tGetDisplayData
!=
null
)
{
_tGetDisplayData
.
Abort
();
}
_tGetDisplayData
=
new
Thread
(
DisplayDataThProc
);
_tGetDisplayData
.
Priority
=
ThreadPriority
.
Highest
;
// _tGetAnalyzerData.IsBackground = true;
_tGetDisplayData
.
Start
();
}
/// <summary>
/// 判断线程工作状态
/// </summary>
/// <returns></returns>
public
bool
ThreadWorking
()
{
if
(
_tGetDisplayData
!=
null
)
{
if
(
_tGetDisplayData
.
ThreadState
==
ThreadState
.
Running
||
(
_tGetDisplayData
.
ThreadState
&
ThreadState
.
WaitSleepJoin
)
!=
0
)
return
true
;
else
return
false
;
}
return
false
;
}
/// <summary>
/// 线程停止
/// </summary>
public
void
DisplayDataThStop
()
{
displaydata_mre
.
Set
();
}
/// <summary>
/// 线程工作函数
/// </summary>
private
void
DisplayDataThProc
()
{
while
(!
displaydata_mre
.
WaitOne
(
1000
))
{
ReadDisplayData
();
}
}
private
void
ReadDisplayData
()
{
MoudbusOperation
.
GetInstance
().
GetGCTemp
();
MoudbusOperation
.
GetInstance
().
GetValveState
();
MoudbusOperation
.
GetInstance
().
GetALLSWState
();
MoudbusOperation
.
GetInstance
().
GetFireState
();
MoudbusOperation
.
GetInstance
().
GetErrorState
();
}
}
}
GcDevicePc/ProThread/HmiStatueTh.cs
0 → 100644
View file @
eb024034
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
GcDevicePc.Common
;
namespace
GcDevicePc.ProThread
{
class
HmiStatueTh
{
/// <summary>
/// 单实例对象
/// </summary>
private
static
HmiStatueTh
instance
=
null
;
//静态私有成员变量
/// <summary>
/// 单实例对象锁
/// </summary>
private
static
object
_lock
=
new
object
();
/// <summary>
/// 数据锁
/// </summary>
private
static
object
_datalock
=
new
object
();
#
region
单实例实现
public
static
HmiStatueTh
GetInstance
()
{
if
(
instance
==
null
)
{
lock
(
_lock
)
{
if
(
instance
==
null
)
{
instance
=
new
HmiStatueTh
();
}
}
}
return
instance
;
}
#
endregion
#
region
分析仪数据读取线程
private
Thread
_tGetHmiStatue
;
//分析仪读取线程
private
ManualResetEvent
hmistatus_mre
=
new
ManualResetEvent
(
false
);
//信号控制量
#
endregion
public
void
HmiStatueThStart
()
{
if
(
hmistatus_mre
!=
null
)
{
hmistatus_mre
.
Reset
();
}
if
(
_tGetHmiStatue
!=
null
)
{
_tGetHmiStatue
.
Abort
();
}
_tGetHmiStatue
=
new
Thread
(
HmiStatueThProc
);
_tGetHmiStatue
.
Priority
=
ThreadPriority
.
Highest
;
// _tGetAnalyzerData.IsBackground = true;
_tGetHmiStatue
.
Start
();
}
/// <summary>
/// 判断线程工作状态
/// </summary>
/// <returns></returns>
public
bool
ThreadWorking
()
{
if
(
_tGetHmiStatue
!=
null
)
{
if
(
_tGetHmiStatue
.
ThreadState
==
ThreadState
.
Running
||
(
_tGetHmiStatue
.
ThreadState
&
ThreadState
.
WaitSleepJoin
)
!=
0
)
return
true
;
else
return
false
;
}
return
false
;
}
/// <summary>
/// 线程停止
/// </summary>
public
void
HmiStatueThStop
()
{
hmistatus_mre
.
Set
();
}
/// <summary>
/// 线程工作函数
/// </summary>
private
void
HmiStatueThProc
()
{
while
(!
hmistatus_mre
.
WaitOne
(
1000
))
{
ReadHmiStatue
();
}
}
private
void
ReadHmiStatue
()
{
MoudbusOperation
.
GetInstance
().
GetHMIStatusData
();
}
}
}
GcDevicePc/ProThread/ThreadMonitor.cs
0 → 100644
View file @
eb024034
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
GcDevicePc.Common
;
namespace
GcDevicePc.ProThread
{
class
ThreadMonitor
{
#
region
检查线程时间
private
ushort
monitortimer
=
1000
*
30
;
//线程检查时间
#
endregion
#
region
单实例实现
private
static
ThreadMonitor
instance
=
null
;
//静态私有成员变量
private
static
object
_lock
=
new
object
();
public
static
ThreadMonitor
GetInstance
()
{
if
(
instance
==
null
)
{
lock
(
_lock
)
{
if
(
instance
==
null
)
{
instance
=
new
ThreadMonitor
();
}
}
}
return
instance
;
}
#
endregion
#
region
连接中心初始化所有读取线程
/// <summary>
/// 显示数据
/// </summary>
private
DisplayDataTh
displayDataTh
=
DisplayDataTh
.
GetInstance
();
/// <summary>
/// 状态数据
/// </summary>
private
HmiStatueTh
hmiStatueTh
=
HmiStatueTh
.
GetInstance
();
/// <summary>
/// 信号数据
/// </summary>
private
ChannelDataTh
channelDataTh
=
ChannelDataTh
.
GetInstance
();
#
endregion
#
region
通讯中心功能函数
/// <summary>
/// 开启所有通讯线程
/// </summary>
public
void
StartALLCommunication
()
{
if
(!
displayDataTh
.
ThreadWorking
())
displayDataTh
.
DisplayDataThStart
();
if
(!
hmiStatueTh
.
ThreadWorking
())
hmiStatueTh
.
HmiStatueThStart
();
if
(!
channelDataTh
.
ThreadWorking
())
channelDataTh
.
ChannelDataThStart
();
}
/// <summary>
/// 关闭所有通讯线程
/// </summary>
public
void
StopALLCommunication
()
{
if
(
displayDataTh
.
ThreadWorking
())
displayDataTh
.
DisplayDataThStop
();
if
(
hmiStatueTh
.
ThreadWorking
())
hmiStatueTh
.
HmiStatueThStop
();
if
(
channelDataTh
.
ThreadWorking
())
channelDataTh
.
ChannelDataThStop
();
}
#
endregion
#
region
通讯中心线程检查进程
private
Thread
_tThreadMonitor
;
//分析仪读取线程
private
ManualResetEvent
monitor_mre
=
new
ManualResetEvent
(
false
);
//信号控制量
public
void
MonitorThStart
()
{
if
(
monitor_mre
!=
null
)
{
monitor_mre
.
Reset
();
}
if
(
_tThreadMonitor
!=
null
)
{
_tThreadMonitor
.
Abort
();
}
_tThreadMonitor
=
new
Thread
(
MonitorThProc
);
// _tThreadMonitor.IsBackground = true;
_tThreadMonitor
.
Start
();
}
public
bool
ThreadWorking
()
{
if
(
_tThreadMonitor
!=
null
)
{
if
(
_tThreadMonitor
.
ThreadState
==
ThreadState
.
Running
||
(
_tThreadMonitor
.
ThreadState
&
ThreadState
.
WaitSleepJoin
)
!=
0
)
return
true
;
else
return
false
;
}
return
false
;
}
public
void
MonitorThStop
()
{
monitor_mre
.
Set
();
}
/// <summary>
/// 判断是否所有通讯线程已经退出
/// </summary>
/// <returns></returns>
public
bool
AllIsClosed
()
{
int
ret
=
0
;
if
(
displayDataTh
.
ThreadWorking
())
{
ret
+=
1
;
}
if
(
hmiStatueTh
.
ThreadWorking
())
{
ret
+=
1
;
}
if
(
channelDataTh
.
ThreadWorking
())
{
ret
+=
1
;
}
return
ret
==
0
?
true
:
false
;
}
/// <summary>
/// 每一分钟监测一次 最小做样是2min
/// </summary>
private
void
MonitorThProc
()
{
while
(!
monitor_mre
.
WaitOne
(
monitortimer
))
{
if
(!
displayDataTh
.
ThreadWorking
())
{
Log
.
Info
(
"数据显示线程 重启"
);
displayDataTh
.
DisplayDataThStart
();
}
if
(!
hmiStatueTh
.
ThreadWorking
())
{
Log
.
Info
(
"HMI状态线程 重启"
);
hmiStatueTh
.
HmiStatueThStart
();
}
if
(!
channelDataTh
.
ThreadWorking
())
{
Log
.
Info
(
"信号线程线程 重启"
);
channelDataTh
.
ChannelDataThStart
();
}
}
}
#
endregion
}
}
GcDevicePc/StartForm.cs
View file @
eb024034
...
...
@@ -156,6 +156,8 @@ namespace GcDevicePc
globaldata
.
m_appinit
.
InitAppFolderGC
();
_appInitInfo
=
"载入方法配置"
;
globaldata
.
m_appinit
.
InitAppDefaultConfig
();
_appInitInfo
=
"启动检测线程"
;
globaldata
.
m_appinit
.
StartDataThread
();
}
private
void
StartFormbgWorker_DoWork
(
object
sender
,
DoWorkEventArgs
e
)
...
...
GcDevicePc/globaldata.cs
View file @
eb024034
...
...
@@ -3,7 +3,7 @@ using System.Collections;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
GcDevicePc.Common
;
using
GcDevicePc.IniParam
;
using
GcDevicePc.GCBuffer
;
...
...
@@ -149,8 +149,10 @@ namespace GcDevicePc
public
static
bool
startflag
=
false
;
//开始按键的标志位
public
static
bool
startclear
=
false
;
//清除开始按键之前的数据
public
static
bool
stopflag
=
false
;
//停止按键的标志位
public
static
bool
stopflag
=
false
;
//停止按键的标志位
public
static
bool
cancelflag
=
false
;
//取消按键的标志位
public
static
GCModbus
global_moudbus
=
new
GCModbus
();
}
}
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