📄 dk20dieselizedynamotordlg.cpp
字号:
m_TCShow.SetCurSel(0);
m_lbWarning.Create(WS_CHILD|WS_VSCROLL|WS_VISIBLE|LBS_DISABLENOSCROLL,CRect(1,644,1278,734),this,0);
m_btnExit.MoveWindow(CRect(150,735,250,765));//(1150,735,1250,765)
fTEMP1 = 0 ;
fTEMP2 = 0 ;
fTEMP3 = 0 ;
dlgSetting.GetSettingToModule();
m_bKillThread = FALSE ;
m_thread = NULL ;
thread_info.hWnd = (HWND)this;
thread_info.Para_1 = NULL;
thread_info.Para_2 = NULL;
thread_info.lpKillThread = &m_bKillThread;
m_thread = AfxBeginThread(ProcLoop1, (LPVOID) &m_bKillThread);
m_bKillThread1 = FALSE ;
m_thread1 = NULL ;
thread_info1.hWnd = (HWND)this;
thread_info1.Para_1 = NULL;
thread_info1.Para_2 = NULL;
thread_info1.lpKillThread = &m_bKillThread1;
m_thread1=AfxBeginThread(SendComdata1,(LPVOID)&m_bKillThread1);
m_bKillThread2 = FALSE ;
m_thread2 = NULL ;
thread_info2.hWnd = (HWND)this;
thread_info2.Para_1 = NULL;
thread_info2.Para_2 = NULL;
thread_info2.lpKillThread = &m_bKillThread2;
m_thread2=AfxBeginThread(SendComdata2,(LPVOID)&m_bKillThread2);
m_bKillThread3 = FALSE ;
m_thread3 = NULL ;
thread_info3.hWnd = (HWND)this;
thread_info3.Para_1 = NULL;
thread_info3.Para_2 = NULL;
thread_info3.lpKillThread = &m_bKillThread3;
m_thread3=AfxBeginThread(SendComdata3,(LPVOID)&m_bKillThread3);
return TRUE; // return TRUE unless you set the focus to a control
}
void CDK20DieselizeDynamotorDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CDK20DieselizeDynamotorDlg::OnPaint()
{
CPaintDC dc(this);
CRect rcClient ; //窗口大小
GetClientRect(&rcClient) ;
CDC memDc ;
memDc.CreateCompatibleDC(&dc) ;
CBitmap bitmap1 ;
bitmap1.CreateCompatibleBitmap(&dc , rcClient.Width(),rcClient.Height()) ;
CBitmap *oldBitmp1 = memDc.SelectObject(&bitmap1) ;
memDc.FillSolidRect(&rcClient , RGB(173,211,198)) ;
CRect rc2(0 , 623 , 1280, 643) ;
DrawGradientFill(&memDc , &rc2 , RGB(244,198,93) ,RGB(237,231,205),5) ;
memDc.SetTextColor(RGB(0,0,0)) ;
memDc.SetBkMode(TRANSPARENT) ;
//memDc.DrawText(m_strDate, &m_rcDbclick , DT_CENTER|DT_VCENTER ); //设定记录日期
if (bChinese)
{
memDc.DrawText(_T("<<实时报警信息>>"), &rc2 , DT_LEFT |DT_VCENTER );
}
else
{
memDc.DrawText(_T("<<Real-time Warning-Information>>"), &rc2 , DT_LEFT |DT_VCENTER );
}
memDc.FillSolidRect(CRect(0,0,1280 , 60), RGB(31, 78 , 100) ) ;
CFont *oldFont = memDc.SelectObject(&m_font) ;
memDc.SetTextColor(RGB(163,255,255)) ;
memDc.SetBkMode(TRANSPARENT) ;
if (bChinese)
{
memDc.DrawText(_T("DK20柴油机发电机组监控"),CRect(240,10 ,1280,43),DT_CENTER |DT_VCENTER ) ;
}
else
{
memDc.DrawText(_T("DK20 Diesel Dynamotor Inspect"),CRect(240,10 ,1280,43),DT_CENTER |DT_VCENTER ) ;
}
memDc.SelectObject(oldFont) ;
dc.BitBlt(0,0,rcClient.Width() , rcClient.Height() , &memDc , 0,0,SRCCOPY) ;
memDc.SelectObject(oldBitmp1) ;
bitmap1.DeleteObject() ;
memDc.DeleteDC() ;
CDC dc2 ;
dc2.CreateCompatibleDC(&dc) ;
CBitmap bitmap ;
bitmap.LoadBitmap(IDB_BITMAP_TITLE) ;
CBitmap* oldBitmap = dc2.SelectObject(&bitmap) ;
dc.BitBlt(0,0,187 , 54,&dc2,0,0,SRCCOPY) ;
dc2.SelectObject(oldBitmap) ;
bitmap.DeleteObject() ;
dc2.DeleteDC() ;
DeleteObject(oldBitmp1) ; oldBitmp1 =NULL ;
DeleteObject(oldBitmap) ; oldBitmap =NULL ;
DeleteObject(oldFont) ; oldFont =NULL ;
ReleaseDC(&dc) ;
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CDK20DieselizeDynamotorDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CDK20DieselizeDynamotorDlg::OnButtonExit()
{
int iRet ;
iRet =MessageBox(_T("退出监控程序?"),_T("退出程序"),MB_YESNO|MB_ICONQUESTION) ;
if (iRet ==IDYES )
{
m_bKillThread1 =TRUE ;
WaitForSingleObject(m_thread1->m_hThread,5000);
byteArray1[0] ='@' ;
byteArray1[1] ='0' ;
byteArray1[2] ='6' ;
byteArray1[3] ='0' ;
byteArray1[4] ='0' ;
byteArray1[5] ='0' ;
byteArray1[6] ='0' ;
byteArray1[7] =0x0D ;
byteArray1[8] ='0' ;
m_pSerial1->WritePort((char*)byteArray1 ,8) ;
m_pSerial1->WaitForResponse(strData1 , WAITDELAY) ;
m_bKillThread2 =TRUE ;
WaitForSingleObject(m_thread2->m_hThread,5000);
byteArray2[0] ='@' ;
byteArray2[1] ='0' ;
byteArray2[2] ='6' ;
byteArray2[3] ='0' ;
byteArray2[4] ='0' ;
byteArray2[5] ='0' ;
byteArray2[6] ='0' ;
byteArray2[7] =0x0D ;
byteArray2[8] ='0';
m_pSerial2->WritePort((char*)byteArray2 ,8) ;
m_pSerial2->WaitForResponse(strData2 , WAITDELAY) ;
m_bKillThread3 =TRUE ;
WaitForSingleObject(m_thread3->m_hThread,5000);
byteArray3[0] ='@' ;
byteArray3[1] ='0' ;
byteArray3[2] ='6' ;
byteArray3[3] ='0' ;
byteArray3[4] ='0' ;
byteArray3[5] ='0' ;
byteArray3[6] = '0';
byteArray3[7] =0x0D ;
byteArray3[8] ='0' ;
m_pSerial3->WritePort((char*)byteArray3 ,8) ;
m_pSerial3->WaitForResponse(strData3 , WAITDELAY) ;
m_bKillThread =TRUE ;
WaitForSingleObject(m_thread->m_hThread,5000);
SendMessage(WM_CLOSE) ;
}
}
void CDK20DieselizeDynamotorDlg::OnSelchangeTab1(NMHDR* pNMHDR, LRESULT* pResult)
{
int CurSel;
CurSel=m_TCShow.GetCurSel();
switch(CurSel)
{
case 0:
dlgImport.ShowWindow(TRUE);
dlgAll.ShowWindow(FALSE);
dlgDrang.ShowWindow(FALSE);
dlgTemperature.ShowWindow(FALSE);
dlgPrinter.ShowWindow(FALSE);
dlgSetting.ShowWindow(FALSE);
break;
case 1:
dlgImport.ShowWindow(FALSE);
dlgAll.ShowWindow(TRUE);
dlgDrang.ShowWindow(FALSE);
dlgTemperature.ShowWindow(FALSE);
dlgPrinter.ShowWindow(FALSE);
dlgSetting.ShowWindow(FALSE);
break;
case 2:
dlgImport.ShowWindow(FALSE);
dlgAll.ShowWindow(FALSE);
dlgDrang.ShowWindow(TRUE);
dlgTemperature.ShowWindow(FALSE);
dlgPrinter.ShowWindow(FALSE);
dlgSetting.ShowWindow(FALSE);
break;
case 3:
dlgImport.ShowWindow(FALSE);
dlgAll.ShowWindow(FALSE);
dlgDrang.ShowWindow(FALSE);
dlgTemperature.ShowWindow(TRUE);
dlgPrinter.ShowWindow(FALSE);
dlgSetting.ShowWindow(FALSE);
break;
case 4:
dlgImport.ShowWindow(FALSE);
dlgAll.ShowWindow(FALSE);
dlgDrang.ShowWindow(FALSE);
dlgTemperature.ShowWindow(FALSE);
dlgPrinter.ShowWindow(TRUE);
dlgSetting.ShowWindow(FALSE);
break;
case 5:
dlgImport.ShowWindow(FALSE);
dlgAll.ShowWindow(FALSE);
dlgDrang.ShowWindow(FALSE);
dlgTemperature.ShowWindow(FALSE);
dlgPrinter.ShowWindow(FALSE);
dlgSetting.ShowWindow(TRUE);
default: ;
}
*pResult = 0;
}
void CDK20DieselizeDynamotorDlg::DrawGradientFill(CDC *pDC, CRect *pRect, COLORREF crStart, COLORREF crEnd, int nSegments)
{
COLORREF cr;
int nR = GetRValue(crStart);
int nG = GetGValue(crStart);
int nB = GetBValue(crStart);
int neB = GetBValue(crEnd);
int neG = GetGValue(crEnd);
int neR = GetRValue(crEnd);
if(nSegments > pRect->Height())
nSegments = pRect->Height();
int nDiffR = (neR - nR);
int nDiffG = (neG - nG);
int nDiffB = (neB - nB);
int ndR = 256 * (nDiffR) / (max(nSegments,1));
int ndG = 256 * (nDiffG) / (max(nSegments,1));
int ndB = 256 * (nDiffB) / (max(nSegments,1));
nR *= 256;
nG *= 256;
nB *= 256;
neR *= 256;
neG *= 256;
neB *= 256;
int nCY = pRect->Height() / max(nSegments,1), nTop = pRect->top , nBottom =nTop;
CPen *hpen =(CPen*) pDC->SelectStockObject(NULL_PEN);
for (int i = 0; i < nSegments; i++, nR += ndR, nG += ndG, nB += ndB)
{
if (i == (nSegments - 1))
nTop = pRect->bottom;
else
nTop += nCY;
cr = RGB(nR / 256, nG / 256, nB / 256);
CBrush br(cr);
CBrush* pbrOld = pDC->SelectObject(&br);
pDC->Rectangle(pRect->left, nTop+1, pRect->right , nBottom);
pDC->SelectObject(pbrOld);
br.DeleteObject() ;
DeleteObject(pbrOld) ;
pbrOld =NULL ;
nBottom = nTop ;
}
pDC->SelectObject(hpen) ;
DeleteObject(hpen) ;
hpen = NULL ;
}
void CDK20DieselizeDynamotorDlg::SetModeChinese()
{
//初始化虚拟模块 每个模块都有很多的值项 , 每个值项都需要初始化出相应的值对应的名称
//iCurrentvalue 读取到的当前值 iWarningvalue 超过这个值就需要报警 ,strValuename 当前的值对应的内容
for (int i=0;i<3;i++)
{
MOUDLE_VALUE moudleItem ; //单点临时变量
moudleItem.iCurrentvalue =-100.0f ; //当取-100的时候就是异常数据并未获取到数据
//模块1 7015
//模块名称 :温度1
//模块值项目:3个
//传感器:pt100
//高温水出机温度
//低温水出机温度
//滑油进机温度
moudleItem.iTotalCount = 3 ;
moudle[5*i].strCommand = _T("moudle1") ;
//1
moudleItem.iStatus = 0 ;
moudleItem.iWarningvalueuper =44.0f ;
moudleItem.strValuename =_T("高温水出机温度") ;
moudle[5*i].vcorValue[0] =moudleItem ;
//2
moudleItem.iStatus = 0 ;
moudleItem.iWarningvalueuper =32.0f ;
moudleItem.strValuename =_T("低温水进机温度") ;
moudle[5*i].vcorValue[1] =moudleItem ;
//3
moudleItem.iStatus = 0 ;
moudleItem.iWarningvalueuper =32.0f ;
moudleItem.strValuename =_T("滑油进机温度") ;
moudle[5*i].vcorValue[2] =moudleItem ;
//模块2 7018z-g/s
//模块名称 :温度2
//模块值项目:10个
//传感器:k值热电偶
//1#缸排温温度
//2#缸排温温度
//3#缸排温温度
//4#缸排温温度
//5#缸排温温度
//6#缸排温温度
//7#缸排温温度
//8#缸排温温度
//增压器进口排气温度
//增压器出口废气温度
moudleItem.iTotalCount = 10 ;
moudle[5*i+1].strCommand = _T("moudle2") ;
//1
moudleItem.iStatus = 0 ;
moudleItem.iWarningvalueuper =32.0f ;
moudleItem.strValuename =_T("1#缸排温度");
moudle[5*i+1].vcorValue[0] = moudleItem ;
//2
moudleItem.iStatus = 0 ;
moudleItem.iWarningvalueuper =32.0f ;
moudleItem.strValuename =_T("2#缸排温度") ;
moudle[5*i+1].vcorValue[1] = moudleItem ;
//3
moudleItem.iStatus = 0 ;
moudleItem.iWarningvalueuper =32.0f ;
moudleItem.strValuename =_T("3#缸排温度") ;
moudle[5*i+1].vcorValue[2] = moudleItem ;
//4
moudleItem.iStatus = 0 ;
moudleItem.iWarningvalueuper =32.0f ;
moudleItem.strValuename =_T("4#缸排温度") ;
moudle[5*i+1].vcorValue[3] = moudleItem ;
//5
moudleItem.iStatus = 0 ;
moudleItem.iWarningvalueuper =32.0f ;
moudleItem.strValuename =_T("5#缸排温度") ;
moudle[5*i+1].vcorValue[4] = moudleItem ;
//6
moudleItem.iStatus = 0 ;
moudleItem.iWarningvalueuper =32.0f ;
moudleItem.strValuename ="6#缸排温度" ;
moudle[5*i+1].vcorValue[5] = moudleItem ;
//7
moudleItem.iStatus = 0 ;
moudleItem.iWarningvalueuper =32.0f ;
moudleItem.strValuename =_T("7#缸排温度") ;
moudle[5*i+1].vcorValue[6] = moudleItem ;
//8
moudleItem.iStatus = 0 ;
moudleItem.iWarningvalueuper =32.0f ;
moudleItem.strValuename =_T("8#缸排温度") ;
moudle[5*i+1].vcorValue[7] = moudleItem ;
//9
moudleItem.iStatus = 0 ;
moudleItem.iWarningvalueuper =32.0f ;
moudleItem.strValuename =_T("增压器进口排气温度") ;
moudle[5*i+1].vcorValue[8] = moudleItem ;
//10
moudleItem.iStatus = 0 ;
moudleItem.iWarningvalueuper =32.0f ;
moudleItem.strValuename =_T("增压器出口废气温度") ;
moudle[5*i+1].vcorValue[9] = moudleItem ;
//模块3 7017 -1
//模块名称 :温度和压力
//模块值项目:8个
//传感器:4-20ma
//发电机轴承前端温度
//发电机轴承后端温度
//发电机1#定子绕组温度
//发电机2#定子绕组温度
//发电机3#定子绕组温度
//高温水进口压力
//滑油进机压力
//滑油滤器压力差
moudleItem.iTotalCount = 8 ;
moudle[5*i+2].strCommand = _T("moudle3") ;
//1
moudleItem.iStatus = 0 ;
moudleItem.iWarningvalueuper =0.2f ;
moudleItem.strValuename =_T("发电机轴承前端温度") ;
moudle[5*i+2].vcorValue[0] = moudleItem ;
//2
moudleItem.iStatus = 0 ;
moudleItem.iWarningvalueuper =0.05f ;
moudleItem.strValuename =_T("发电机轴承后端温度") ;
moudle[5*i+2].vcorValue[1] = moudleItem ;
//3
moudleItem.iStatus = 0 ;
moudleItem.iWarningvalueuper =0.45f ;
moudleItem.strValuename =_T("发电机U#定子绕组温度") ;
moudle[5*i+2].vcorValue[2] = moudleItem ;
//4
moudleItem.iStatus = 0 ;
moudleItem.iWarningvalueuper =0.25f ;
moudleItem.strValuename =_T("发电机V#定子绕组温度") ;
moudle[5*i+2].vcorValue[3] = moudleItem ;
//5
moudleItem.iStatus = 0 ;
moudleItem.iWarningvalueuper =0.1f ;
moudleItem.strValuename =_T("发电机W#定子绕组温度") ;
moudle[5*i+2].vcorValue[4] = moudleItem ;
//6
moudleItem.iStatus = 0 ;
moudleItem.iWarningvalueuper =0.2f ;
moudleItem.strValuename =_T("增压器转速") ;
moudle[5*i+2].vcorValue[5] = moudleItem ;
//7
moudleItem.iStatus = 0 ;
moudleItem.iWarningvalueuper =0.1f ;
moudleItem.strValuename =_T("高温水进口压力") ;
moudle[5*i+2].vcorValue[6] = moudleItem ;
//8
moudleItem.iStatus = 0 ;
moudleItem.iWarningvalueuper =0.08f ;
moudleItem.strValuename =_T("滑油进机压力");
moudle[5*i+2].vcorValue[7] = moudleItem ;
//模块4 7017 -2
//模块名称 :压力和转速
//模块值项目:6个
//传感器:4-20ma
//燃油进机压力
//起动空气压力
//控制空气压力
//低温水进口压力
//燃油压力(柴油)
//增压器转速
moudleItem.iTotalCount = 6 ;
moudle[5*i+3].strCommand = _T("moudle4") ;
//1
moudleItem.iStatus = 0 ;
moudleItem.iWarningvalueuper =0.2f ;
moudleItem.strValuename =_T("滑油滤器压力差") ;
moudle[5*i+3].vcorValue[0] = moudleItem ;
//2
moudleItem.iStatus = 0 ;
moudleItem.iWarningvalueuper =0.05f ;
moudleItem.strValuename =_T("燃油进机压力") ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -