📄 progressmanamgedlg.cpp
字号:
dlgDate.m_sOpration += "号看板的'设定新值数据'";
dlgDate.m_sOpration +="\r\n";
if(recentMatchine == matchId)
copyDateFromDlgDate(dlgDate);
}
matchineData[matchId] = dlgDate;
/* ((CButton *)GetDlgItem(recentMatchine))->SetCheck(FALSE);
recentMatchine = matchId;
((CButton *)GetDlgItem(matchId))->SetCheck(TRUE);*/
lastFactUp = CTime::GetCurrentTime();
UpdateData(FALSE);
}
// returnMessage(factSetupUpSuccessPrefix);
break;
case planUpSendPrefix:
// MessageBox("plan received data!");
{
if(!validateData(rxdata,len)){
// returnMessage(planUpFailPrefix);
return;
}
CString tempsSetup = _T("");
for(index =2;index<=5;){
if(rxdata[index]==0 && tempsSetup.IsEmpty())
{
index++;
continue;
}
temp.Format("%x",rxdata[index]);
tempsSetup += temp;
index++;
}
if(tempsSetup.IsEmpty())
tempsSetup="0";
saveOldData();
int matchId=getMatchIdByDirectory(rxdata[1]);
CString matchineMessage;
matchineMessage.Format("%d",rxdata[1]+1);
//CString massage;
//massage.Format("%d",matchId);
// MessageBox("recentId="+massage);
map<int,DlgDate>::iterator it = matchineData.find(matchId);
DlgDate dlgDate;
if(it!=matchineData.end())
{
dlgDate= it->second;
dlgDate.m_sPlan = tempsSetup;
/*if (!dlgDate.m_sFact.IsEmpty())
{
temp.Format("%d",atoi(dlgDate.m_sFact)-atoi(dlgDate.m_sPlan));
dlgDate.m_sDiviation=temp;
}*/
dlgDate.m_sOpration += "接收";
dlgDate.m_sOpration += matchineMessage;
dlgDate.m_sOpration += "号看板的'计划原来数据'";
dlgDate.m_sOpration +="\r\n";
if(recentMatchine == matchId){
changeShowIcon();
copyDateFromDlgDate(dlgDate);
}
}
else{
dlgDate.m_sPlan = tempsSetup;
dlgDate.m_sOpration += "接收";
dlgDate.m_sOpration += matchineMessage;
dlgDate.m_sOpration += "号看板的'计划原来数据'";
dlgDate.m_sOpration +="\r\n";
if(recentMatchine == matchId){
changeShowIcon();
copyDateFromDlgDate(dlgDate);
}
}
/* ((CButton *)GetDlgItem(recentMatchine))->SetCheck(FALSE);
recentMatchine = matchId;
((CButton *)GetDlgItem(matchId))->SetCheck(TRUE);*/
// returnMessage(planUpSuccessPrefix);
matchineData[matchId] = dlgDate;
UpdateData(FALSE);
}
break;
case planDownSuccessPrefix:
// MessageBox("received successful!");
if(sendPlan){
KillTimer(IDT_TIMER_PLAN);
sendPlan = FALSE;
}
break;
case planDownFailPrefix:
/* if(!sendPlan){
iPlanSendCount = 0;
sendPlan = TRUE;
SetTimer(IDT_TIMER_PLAN,elapseTime,NULL);
}*/
break;
case factUpSendPrefix:
{
if(!validateData(rxdata,len)){
// returnMessage(factUpFailPrefix);
return;
}
CString tempsSetup = _T("");
for(index =2;index<=5;){
if(rxdata[index]==0 && tempsSetup.IsEmpty())
{
index++;
continue;
}
temp.Format("%x",rxdata[index]);
tempsSetup += temp;
index++;
}
if(tempsSetup.IsEmpty())
tempsSetup="0";
saveOldData();
int matchId=getMatchIdByDirectory(rxdata[1]);
CString matchineMessage;
matchineMessage.Format("%d",rxdata[1]+1);
map<int,DlgDate>::iterator it = matchineData.find(matchId);
DlgDate dlgDate;
if(it!=matchineData.end())
{
dlgDate= it->second;
dlgDate.m_sFact = tempsSetup;
if (!dlgDate.m_sSetup.IsEmpty())
{
temp.Format("%d",atoi(dlgDate.m_sFact)-atoi(dlgDate.m_sSetup));
dlgDate.m_sDiviation=temp;
}
dlgDate.m_sOpration += "接收";
dlgDate.m_sOpration += matchineMessage;
dlgDate.m_sOpration += "号看板的'实际原来数据'";
dlgDate.m_sOpration +="\r\n";
if(recentMatchine == matchId){
copyDateFromDlgDate(dlgDate);
changeShowIcon();
}
}
else{
dlgDate.m_sFact = tempsSetup;
dlgDate.m_sOpration += "接收";
dlgDate.m_sOpration += matchineMessage;
dlgDate.m_sOpration += "号看板的'实际原来数据'";
dlgDate.m_sOpration +="\r\n";
if(recentMatchine == matchId){
copyDateFromDlgDate(dlgDate);
changeShowIcon();
}
}
/* ((CButton *)GetDlgItem(recentMatchine))->SetCheck(FALSE);
recentMatchine = matchId;
((CButton *)GetDlgItem(matchId))->SetCheck(TRUE);*/
matchineData[matchId] = dlgDate;
lastFactUp = CTime::GetCurrentTime();
UpdateData(FALSE);
}
// returnMessage(factUpSuccessPrefix);
break;
case factDownSuccessPrefix:
if(sendFact){
KillTimer(IDT_TIMER_FACT);
sendFact = FALSE;
}
break;
case factDownFailPrefix:
/*if(!sendFact){
iFactSendCount = 0;
sendFact = TRUE;
SetTimer(IDT_TIMER_FACT,elapseTime,NULL);
}*/
break;
case perFactUpSendPrefix:
{
if(!validateData(rxdata,len)){
// returnMessage(factUpFailPrefix);
return;
}
CString tempsSetup = _T("");
for(index =2;index<=5;){
if(rxdata[index]==0 && tempsSetup.IsEmpty())
{
index++;
continue;
}
temp.Format("%x",rxdata[index]);
tempsSetup += temp;
index++;
}
if(tempsSetup.IsEmpty())
tempsSetup="0";
saveOldData();
int matchId=getMatchIdByDirectory(rxdata[1]);
CString matchineMessage;
matchineMessage.Format("%d",rxdata[1]+1);
map<int,DlgDate>::iterator it = matchineData.find(matchId);
DlgDate dlgDate;
if(it!=matchineData.end())
{
dlgDate= it->second;
dlgDate.perFact = tempsSetup;
/* if (!dlgDate.m_sPlan.IsEmpty())
{
temp.Format("%d",atoi(dlgDate.m_sFact)-atoi(dlgDate.m_sPlan));
dlgDate.m_sDiviation=temp;
}
*/
dlgDate.m_sOpration += "接收";
dlgDate.m_sOpration += matchineMessage;
dlgDate.m_sOpration += "机的'实际新值数据'";
dlgDate.m_sOpration +="\r\n";
if(recentMatchine == matchId)
copyDateFromDlgDate(dlgDate);
}
else{
dlgDate.perFact = tempsSetup;
dlgDate.m_sOpration += "接收";
dlgDate.m_sOpration += matchineMessage;
dlgDate.m_sOpration += "机的'实际新值数据'";
dlgDate.m_sOpration +="\r\n";
if(recentMatchine == matchId)
copyDateFromDlgDate(dlgDate);
}
/* ((CButton *)GetDlgItem(recentMatchine))->SetCheck(FALSE);
recentMatchine = matchId;
((CButton *)GetDlgItem(matchId))->SetCheck(TRUE); */
matchineData[matchId] = dlgDate;
lastFactUp = CTime::GetCurrentTime();
UpdateData(FALSE);
}
break;
case datetimeDownSuccessPrefix:
if (sendDateTime)
{
KillTimer(IDT_TIMER_DATETIME);
sendDateTime =FALSE;
}
break;
case datetimeDownFailPrefix:
/* if (!sendDateTime)
{
iDateSendCount =0;
sendDateTime = TRUE;
SetTimer(IDT_TIMER_DATETIME,elapseTime,NULL);
}*/
break;
default:
break;
}
}
void CProgressManamgeDlg::returnMessage(const char retrunFlag){
CByteArray bety;
int index;
bety.SetSize(sendDataLength);
bety.SetAt(0,retrunFlag);
for(index =1;index<sendDataLength-1;index++)
{
bety.SetAt(index,0);
}
bety.SetAt(sendDataLength-1,retrunFlag);
m_ctrlMSComm.SetOutput(COleVariant(bety));
}
/*
void CProgressManamgeDlg::returnOK(const int flagSend){
CByteArray bety;
int index;
UCHAR affix = 0;
bety.SetSize(sendDataLength);
bety.SetAt(0,flagSend);
for(index =1;index<sendDataLength-1;index++)
{
bety.SetAt(index,0);
}
bety.SetAt(sendDataLength-1,flagSend);
m_ctrlMSComm.SetOutput(COleVariant(bety));
break;
}
}
*/
BOOL CProgressManamgeDlg::validateData(BYTE rxdata[],int len){
UCHAR affix =0;
for (int index =0;index<len-1;index++)
{
affix += rxdata[index];
}
if (affix == rxdata[len-1])
{
return TRUE;
}
else
return FALSE;
}
int CProgressManamgeDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
iTestSendCount = 0;
iDateSendCount = 0;
iFactSendCount = 0;
iPlanSendCount = 0;
iSetupSendCount = 0;
return 0;
}
void CProgressManamgeDlg::OnExit()
{
::AfxGetMainWnd()->SendMessage(WM_CLOSE);
}
void CProgressManamgeDlg::OnClose()
{
// TODO: Add your message handler code here and/or call default
if(MessageBox("确定要退出吗?","退出应用程序对话框", MB_YESNO | MB_ICONINFORMATION) == IDYES)
CDialog::OnClose();
}
void CProgressManamgeDlg::OnButtonTest()
{
// TODO: Add your control notification handler code here
/* iTestSendCount = 0;
sendTest = TRUE;
SetTimer(IDT_TIMER_TEST,elapseTime,NULL);
*/
if (comOpened)
{
if(m_ctrlMSComm.GetPortOpen())
m_ctrlMSComm.SetPortOpen(FALSE);
m_ctlOpenComm.SetWindowText("打开串口");
m_Combo_Com.EnableWindow(TRUE);
comOpened = FALSE;
}
else{
enableMSComm();
}
}
void CProgressManamgeDlg::enableMSComm(){
int commPort = getCommPort();
m_ctrlMSComm.SetCommPort(commPort);
m_ctrlMSComm.SetInputMode(1);
m_ctrlMSComm.SetInBufferSize(1024);
m_ctrlMSComm.SetOutBufferSize(512);
m_ctrlMSComm.SetSettings("9600,n,8,1");
if(!m_ctrlMSComm.GetPortOpen()){
m_ctrlMSComm.SetPortOpen(TRUE);
comOpened = TRUE;
m_Combo_Com.EnableWindow(FALSE);
m_ctlOpenComm.SetWindowText("关闭串口");
// MessageBox("port opend!");
}
}
int CProgressManamgeDlg::getCommPort(){
if (m_strCom == "串口1")
return 1;
if (m_strCom == "串口2")
return 2;
if (m_strCom == "串口3")
return 3;
if (m_strCom == "串口4")
return 4;
if (m_strCom == "串口5")
return 5;
if (m_strCom == "串口6")
return 6;
if (m_strCom == "串口7")
return 7;
if (m_strCom == "串口8")
return 8;
if (m_strCom == "串口9")
return 9;
}
void CProgressManamgeDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
switch(nIDEvent)
{
case IDT_TIMER_TEST:
processTest();
break;
case IDT_TIMER_SETUP:
processSetup();
break;
case IDT_TIMER_FACT:
processFact();
break;
case IDT_TIMER_PLAN:
processPlan();
break;
case IDT_TIMER_DATETIME:
processDateTime();
break;
case IDT_TIMER_CHECKHASRECEIVEDATE:
{
CTime t = CTime::GetCurrentTime();
if (t.GetHour() - lastFactUp.GetHour() >=2 ||
t.GetMinute() - lastFactUp.GetMinute() >=10 ||
(t.GetHour()-lastFactUp.GetHour()==1 && lastFactUp.GetMinute() - t.GetMinute()<=10))
{
m_showState.SetIcon(yellowIcon);
}
break;
}
case IDT_TIMER_CHANGEDATETIME:
CTime tmpT = CTime::GetCurrentTime();
year = tmpT.GetYear();
mouth = tmpT.GetMonth();
day = tmpT.GetDay();
date = tmpT.GetDayOfWeek();
hour = tmpT.GetHour();
minute = tmpT.GetMinute();
second = tmpT.GetSecond();
iDateSendCount = 0 ;
sendDateTime = TRUE;
//SetTimer(IDT_TIMER_DATETIME,elapseTime,NULL);
// processDateTime();
setDateString();
m_sOpration = _T("");
UpdateData(FALSE);
break;
}
}
void CProgressManamgeDlg::processTest(){
if (iTestSendCount == 3)
{
iTestSendCount = 0;
sendTest = FALSE;
KillTimer(IDT_TIMER_TEST);
MessageBox("无法与下位机进行通信!","通信错误对话框",MB_OK | MB_ICONINFORMATION);
}
else{
CByteArray bety;
bety.SetSize(2);
bety.SetAt(0,1);
bety.SetAt(1,2);
m_ctrlMSComm.SetOutput(COleVariant("12"));
iTestSendCount++ ;
if(debugFlag){
UpdateData(TRUE);
m_sOpration += "第";
CString temp;
temp.Format("%d",iTestSendCount);
m_sOpration += temp;
m_sOpration += "次与下位机连接";
m_sOpration += "\r\n";
}
changeShowIcon();
UpdateData(FALSE);
}
}
void CProgressManamgeDlg::processSetup(){
/* if (iSetupSendCount == 3)
{
iSetupSendCount = 0;
sendSetup = FALSE;
KillTimer(IDT_TIMER_SETUP);
MessageBox("无法与下位机进行通信!","通信错误对话框",MB_OK | MB_ICONINFORMATION);
}
else{*/
CByteArray bety;
int index;
UCHAR affix = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -