You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
325 lines
9.7 KiB
C++
325 lines
9.7 KiB
C++
#include "StdAfx.h"
|
|
#include "AllThreadMgr.h"
|
|
#include "CStringFuc.h"
|
|
#include "FileMgr.h"
|
|
#include "WorkTime.h"
|
|
#include "LogMgr.h"
|
|
|
|
CAllThreadMgr gAllThreadMgr;
|
|
bool gbStopAllThread= false;//停止所有线程
|
|
CAllThreadMgr::CAllThreadMgr(void)
|
|
{
|
|
InitThreadInfoVec();
|
|
}
|
|
CAllThreadMgr::~CAllThreadMgr(void)
|
|
{
|
|
}
|
|
//初始化线程容器
|
|
void CAllThreadMgr::InitThreadInfoVec()
|
|
{
|
|
{
|
|
CThreadInfo ThreadInfo;
|
|
ThreadInfo.m_ThreadType = _EThreadType_AutoWorkFlowCtrlThread;
|
|
ThreadInfo.m_ThreadName = "工作流程控制线程";
|
|
m_ThreadInfoVec.push_back(ThreadInfo);
|
|
}
|
|
|
|
{
|
|
CThreadInfo ThreadInfo;
|
|
ThreadInfo.m_ThreadType = _EThreadType_LaserSleepThread;
|
|
ThreadInfo.m_ThreadName = "激光休眠线程";
|
|
m_ThreadInfoVec.push_back(ThreadInfo);
|
|
}
|
|
|
|
{
|
|
CThreadInfo ThreadInfo;
|
|
ThreadInfo.m_ThreadType = _EThreadType_GetDataPtThread,
|
|
ThreadInfo.m_ThreadName = "运行时测量线程";
|
|
m_ThreadInfoVec.push_back(ThreadInfo);
|
|
}
|
|
|
|
{
|
|
CThreadInfo ThreadInfo;
|
|
ThreadInfo.m_ThreadType = _EThreadType_ExecuteStepThread;
|
|
ThreadInfo.m_ThreadName = "步骤执行线程";
|
|
m_ThreadInfoVec.push_back(ThreadInfo);
|
|
}
|
|
{
|
|
CThreadInfo ThreadInfo;
|
|
ThreadInfo.m_ThreadType = _EThreadType_FastReadInfoThread;
|
|
ThreadInfo.m_ThreadName = "状态读取线程(fast)";
|
|
m_ThreadInfoVec.push_back(ThreadInfo);
|
|
}
|
|
{
|
|
CThreadInfo ThreadInfo;
|
|
ThreadInfo.m_ThreadType = _EThreadType_SlowReadInfoThread;
|
|
ThreadInfo.m_ThreadName = "状态读取线程(slow)";
|
|
m_ThreadInfoVec.push_back(ThreadInfo);
|
|
}
|
|
{
|
|
CThreadInfo ThreadInfo;
|
|
ThreadInfo.m_ThreadType = _EThreadType_PlcReadInfoThread;
|
|
ThreadInfo.m_ThreadName = "PLC 通信线程";
|
|
m_ThreadInfoVec.push_back(ThreadInfo);
|
|
}
|
|
{
|
|
CThreadInfo ThreadInfo;
|
|
ThreadInfo.m_ThreadType = _EThreadType_SwitchLaserLddThread;
|
|
ThreadInfo.m_ThreadName = "激光器ldd 线程";
|
|
m_ThreadInfoVec.push_back(ThreadInfo);
|
|
}
|
|
#ifdef __LASER_DEVICE_BEAMTECH__
|
|
{
|
|
CThreadInfo ThreadInfo;
|
|
ThreadInfo.m_ThreadType = _EThreadType_BeamtechSetParToLaserThread;
|
|
ThreadInfo.m_ThreadName = "激光器参数线程";
|
|
m_ThreadInfoVec.push_back(ThreadInfo);
|
|
}
|
|
#endif
|
|
{
|
|
CThreadInfo ThreadInfo;
|
|
ThreadInfo.m_ThreadType = _EThreadType_TimingProgressThread;
|
|
ThreadInfo.m_ThreadName = "进度条线程";
|
|
m_ThreadInfoVec.push_back(ThreadInfo);
|
|
}
|
|
{
|
|
CThreadInfo ThreadInfo;
|
|
ThreadInfo.m_ThreadType = _EThreadType_RecordTimeThread;
|
|
ThreadInfo.m_ThreadName = "记录计时线程";
|
|
m_ThreadInfoVec.push_back(ThreadInfo);
|
|
}
|
|
|
|
{
|
|
CThreadInfo ThreadInfo;
|
|
ThreadInfo.m_ThreadType = _EThreadType_WaitTransferLoadEndThread;
|
|
ThreadInfo.m_ThreadName = "等待load 结束线程";
|
|
m_ThreadInfoVec.push_back(ThreadInfo);
|
|
}
|
|
{
|
|
CThreadInfo ThreadInfo;
|
|
ThreadInfo.m_ThreadType = _EThreadType_CheckTransferLoadThread;
|
|
ThreadInfo.m_ThreadName = "检查是否需要load 的线程";
|
|
m_ThreadInfoVec.push_back(ThreadInfo);
|
|
}
|
|
|
|
{
|
|
CThreadInfo ThreadInfo;
|
|
ThreadInfo.m_ThreadType = _EThreadType_DlgDeviceStateInfoTimer;
|
|
ThreadInfo.m_ThreadName = "状态信息timer1";
|
|
m_ThreadInfoVec.push_back(ThreadInfo);
|
|
}
|
|
{
|
|
CThreadInfo ThreadInfo;
|
|
ThreadInfo.m_ThreadType = _EThreadType_DlgDeviceStateInfoTimer2;
|
|
ThreadInfo.m_ThreadName = "状态信息timer2";
|
|
m_ThreadInfoVec.push_back(ThreadInfo);
|
|
}
|
|
{
|
|
CThreadInfo ThreadInfo;
|
|
ThreadInfo.m_ThreadType = _EThreadType_ReadLaserPower;
|
|
ThreadInfo.m_ThreadName = "功率计线程";
|
|
m_ThreadInfoVec.push_back(ThreadInfo);
|
|
}
|
|
{
|
|
CThreadInfo ThreadInfo;
|
|
ThreadInfo.m_ThreadType = _EThreadType_LaserDisMeterReadThread;
|
|
ThreadInfo.m_ThreadName = "测距仪通信timer";
|
|
m_ThreadInfoVec.push_back(ThreadInfo);
|
|
}
|
|
{
|
|
CThreadInfo ThreadInfo;
|
|
ThreadInfo.m_ThreadType = _EThreadType_ReadLaserInfoThread;
|
|
ThreadInfo.m_ThreadName = "绿激光信息读取线程";
|
|
m_ThreadInfoVec.push_back(ThreadInfo);
|
|
}
|
|
{
|
|
CThreadInfo ThreadInfo;
|
|
ThreadInfo.m_ThreadType = _EThreadType_ReadRedLaserInfoThread;
|
|
ThreadInfo.m_ThreadName = "红光信息读取线程";
|
|
m_ThreadInfoVec.push_back(ThreadInfo);
|
|
}
|
|
{
|
|
CThreadInfo ThreadInfo;
|
|
ThreadInfo.m_ThreadType = _EThreadType_AutoTransferFlowThread;
|
|
ThreadInfo.m_ThreadName = "自动传片测试线程";
|
|
m_ThreadInfoVec.push_back(ThreadInfo);
|
|
}
|
|
{
|
|
CThreadInfo ThreadInfo;
|
|
ThreadInfo.m_ThreadType = _EThreadType_ReadTransferArmInfoThread;
|
|
ThreadInfo.m_ThreadName = "TransferArm 通信线程";
|
|
m_ThreadInfoVec.push_back(ThreadInfo);
|
|
}
|
|
{
|
|
CThreadInfo ThreadInfo;
|
|
ThreadInfo.m_ThreadType = _EThreadType_UpdateSecsDataThread;
|
|
ThreadInfo.m_ThreadName = "SecsVariable 线程";
|
|
m_ThreadInfoVec.push_back(ThreadInfo);
|
|
}
|
|
{
|
|
CThreadInfo ThreadInfo;
|
|
ThreadInfo.m_ThreadType = _EThreadType_CtrlHostJobThread;
|
|
ThreadInfo.m_ThreadName = "CtrlHostJob 线程";
|
|
m_ThreadInfoVec.push_back(ThreadInfo);
|
|
}
|
|
{
|
|
CThreadInfo ThreadInfo;
|
|
ThreadInfo.m_ThreadType = _EThreadType_CyclicRunThread;
|
|
ThreadInfo.m_ThreadName = "CyclicRun 线程";
|
|
m_ThreadInfoVec.push_back(ThreadInfo);
|
|
}
|
|
}
|
|
void CAllThreadMgr::InsertThreadInfoList(CListCtrl &List,bool bInsert)
|
|
{
|
|
if(bInsert)
|
|
List.DeleteAllItems();
|
|
|
|
int size = m_ThreadInfoVec.size();
|
|
for(int i=0;i<size;i++)
|
|
{
|
|
CThreadInfo &ThreadInfo = m_ThreadInfoVec[i];
|
|
int idx = 0;
|
|
if(bInsert)
|
|
{
|
|
List.InsertItem(i," ");//插入一行
|
|
}
|
|
List.SetItemText(i,idx++,Int2CString(i+1));//序号
|
|
List.SetItemText(i,idx++,ThreadInfo.m_ThreadName);//参数名称
|
|
CString s;
|
|
if(ThreadInfo.m_bRunning)
|
|
s = "On";
|
|
else
|
|
s = "Off";
|
|
|
|
List.SetItemText(i,idx++,s);//状态
|
|
}
|
|
}
|
|
//设置线程的运行状态
|
|
void CAllThreadMgr::SetThreadInfoState(EThreadType ThreadType,bool bRunning)
|
|
{
|
|
int size = m_ThreadInfoVec.size();
|
|
for(int i=0;i<size;i++)
|
|
{
|
|
CThreadInfo &ThreadInfo = m_ThreadInfoVec[i];
|
|
if(ThreadInfo.m_ThreadType == ThreadType)
|
|
{
|
|
ThreadInfo.m_bRunning = bRunning;
|
|
break;
|
|
}
|
|
}
|
|
//更新线程时间
|
|
//UpdateThreadTime(ThreadType);
|
|
}
|
|
//更新线程时间
|
|
void CAllThreadMgr::UpdateThreadTime(EThreadType ThreadType)
|
|
{
|
|
int size = m_ThreadInfoVec.size();
|
|
for(int i=0;i<size;i++)
|
|
{
|
|
CThreadInfo &ThreadInfo = m_ThreadInfoVec[i];
|
|
if(ThreadInfo.m_ThreadType == ThreadType)
|
|
{
|
|
CString RunTime;
|
|
CWorkTime WorkTime;
|
|
ThreadInfo.m_LastRunTime = WorkTime.GetDateTime("/",":");
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
COLORREF CAllThreadMgr::GetStateColor(int idx)
|
|
{
|
|
COLORREF c = RGB_GRAY2;
|
|
int size = m_ThreadInfoVec.size();
|
|
if(idx>=0 && idx < size)
|
|
{
|
|
if(m_ThreadInfoVec[idx].m_bRunning)
|
|
{
|
|
c = RGB_GREEN;
|
|
}
|
|
}
|
|
return c;
|
|
}
|
|
//是否有正在运行的线程
|
|
bool CAllThreadMgr::HasThreadRunning()
|
|
{
|
|
int size = m_ThreadInfoVec.size();
|
|
for(int i=0;i<size;i++)
|
|
{
|
|
CThreadInfo &ThreadInfo = m_ThreadInfoVec[i];
|
|
if(ThreadInfo.m_bRunning)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
//显示运行线程的名字
|
|
void CAllThreadMgr::ShowRunningThreadName()
|
|
{
|
|
int size = m_ThreadInfoVec.size();
|
|
for(int i=0;i<size;i++)
|
|
{
|
|
CThreadInfo &ThreadInfo = m_ThreadInfoVec[i];
|
|
if(ThreadInfo.m_bRunning)
|
|
{
|
|
CString s("RunningThread : ");
|
|
s += ThreadInfo.m_ThreadName;
|
|
gLogMgr->WriteDebugLog(s);
|
|
}
|
|
}
|
|
}
|
|
//绑定线程地址
|
|
void CAllThreadMgr::BindingThreadAdr(EThreadType ThreadType,CWinThread*p)
|
|
{
|
|
int size = m_ThreadInfoVec.size();
|
|
for(int i=0;i<size;i++)
|
|
{
|
|
CThreadInfo &ThreadInfo = m_ThreadInfoVec[i];
|
|
if(ThreadInfo.m_ThreadType == ThreadType)
|
|
{
|
|
ThreadInfo.m_pThread = p;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
//将线程运行的时间写到文件中
|
|
void CAllThreadMgr::WriteAllTreadTimeToFile()
|
|
{
|
|
CString FileName = "\\CommPar\\TreadTimeFile.txt";
|
|
CFileMgr FileMgr;
|
|
char filepath[1024];
|
|
FileMgr.GetFullFilePath(filepath,FileName);
|
|
ofstream FileStream;
|
|
FileStream.open(filepath);
|
|
|
|
int size = m_ThreadInfoVec.size();
|
|
for(int i=0;i<size;i++)
|
|
{
|
|
CThreadInfo &ThreadInfo = m_ThreadInfoVec[i];
|
|
FileStream<<ThreadInfo.m_ThreadName<<" "<<ThreadInfo.m_LastRunTime<<"\n";
|
|
}
|
|
FileStream<<endl;
|
|
FileStream.close();
|
|
}
|
|
//查询线程ThreadType 是否在运行
|
|
bool CAllThreadMgr::IsThreadRunning(EThreadType ThreadType)
|
|
{
|
|
int size = m_ThreadInfoVec.size();
|
|
for(int i=0;i<size;i++)
|
|
{
|
|
CThreadInfo &ThreadInfo = m_ThreadInfoVec[i];
|
|
if(ThreadInfo.m_ThreadType == ThreadType)
|
|
{
|
|
return ThreadInfo.m_bRunning;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
void CAllThreadMgr::StopAllThread()
|
|
{
|
|
gbStopAllThread = true;
|
|
}
|
|
bool CAllThreadMgr::IsbStopAllThread()
|
|
{
|
|
return gbStopAllThread;
|
|
} |