📄 communicationdlg.cpp
字号:
// CommunicationDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ZDUSBMP_DUT.h"
#include "CommunicationDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCommunicationDlg dialog
CCommunicationDlg::CCommunicationDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCommunicationDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCommunicationDlg)
m_ComPort = -1;
//}}AFX_DATA_INIT
}
void CCommunicationDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCommunicationDlg)
DDX_Control(pDX, IDC_LIST1, m_TestResult);
DDX_Radio(pDX, IDC_COM1, m_ComPort);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCommunicationDlg, CDialog)
//{{AFX_MSG_MAP(CCommunicationDlg)
ON_BN_CLICKED(IDC_TEST_BUTTON, OnTestButton)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCommunicationDlg message handlers
BOOL CCommunicationDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_ComPort = pParent->mCommuCtrl.ConnectPort;
ThreadProcBegin = FALSE;
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CCommunicationDlg::OnTestButton()
{
// TODO: Add your control notification handler code here
UpdateData(true);
if (ThreadProcBegin) return;
// port disable
pParent->bComPortPresent = FALSE;
//open COM port
if (pParent->m_MSComCtrl.GetPortOpen()){
pParent->m_MSComCtrl.SetPortOpen(FALSE);
}
pParent->m_MSComCtrl.SetCommPort(m_ComPort+1);
pParent->m_MSComCtrl.SetPortOpen(TRUE);
//test and connect to golden sample
//clear data buffer for transmit
pParent->mCommuCtrl.ClearSendBuff();
//clear data buffer for transmit
pParent->mCommuCtrl.SetHandle(CMD_CLASS_BINDWITH);
pParent->mCommuCtrl.SetBindwithCmd(CMD_BINDWITH_QUEST_CONNECT);
//send MprConfigInterfaceGetInfo
m_TestResult.AddString("---------------------------------------");
m_TestResult.AddString("Bind with golden sample");
for (int i=0; i<25; i++){
pParent->SendByteToCOMPort(&pParent->mCommuCtrl.OutBuff[i]);
}
m_TestResult.AddString("Connecting...");
pParent->ProcedureState = STATE_WAIT;
ThreadProcBegin = true;
AfxBeginThread(CommandCheckThread, this);
SetTimer(1001, TIMEOUT, NULL); //timeout 10-Sec
}
void CCommunicationDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
switch (nIDEvent){
case 1001:
KillTimer(1001);
pParent->ProcedureState = STATE_TIMEOUT;
break;
}
CDialog::OnTimer(nIDEvent);
}
void CCommunicationDlg::PumpMessages()
{
MSG msg;
// Handle dialog messages
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if(!IsDialogMessage(&msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
void CCommunicationDlg::OnCancel()
{
// TODO: Add extra cleanup here
//close thread
ThreadProcBegin = FALSE;
Sleep(300);
//close Timer
KillTimer(1001);
//set process at idle
pParent->ProcedureState = STATE_IDLE;
//close com port
if (pParent->m_MSComCtrl.GetPortOpen()){
pParent->m_MSComCtrl.SetPortOpen(FALSE);
}
CDialog::OnCancel();
}
UINT CCommunicationDlg::CommandCheckThread(LPVOID pParam)
{
int i;
CCommunicationDlg* pDlg = (CCommunicationDlg*) pParam;
bool bIsRunning=true;
while (bIsRunning){
switch(pDlg->pParent->ProcedureState){
case STATE_FAIL_RESEND:
pDlg->KillTimer(1001);
pDlg->m_TestResult.AddString("Command fail!!! -- Try again");
for (i=0; i<25; i++){
pDlg->pParent->SendByteToCOMPort(&pDlg->pParent->mCommuCtrl.OutBuff[i]);
}
pDlg->pParent->ProcedureState = STATE_WAIT;
pDlg->SetTimer(1001, TIMEOUT, NULL);
break;
case STATE_OVERTIMES:
pDlg->KillTimer(1001);
pDlg->m_TestResult.AddString("Can't get correct command!!! -- stop");
bIsRunning=FALSE;
break;
case STATE_TIMEOUT:
pDlg->KillTimer(1001);
pDlg->m_TestResult.AddString("Time Out!!! -- stop");
bIsRunning=FALSE;
break;
case STATE_RECEIVER_COMPLETE:
pDlg->KillTimer(1001);
pDlg->m_TestResult.AddString("Completed");
pDlg->pParent->mCommuCtrl.ConnectPort = pDlg->m_ComPort;
pDlg->pParent->bComPortPresent = true;
bIsRunning=FALSE;
break;
default:
break;
}
if (!pDlg->ThreadProcBegin) break;
}
pDlg->ThreadProcBegin = FALSE;
AfxEndThread(0);
TRACE(_T("Close Thread 0\n"));
return 0;
}
void CCommunicationDlg::OnOK()
{
// TODO: Add extra validation here
//close thread
ThreadProcBegin = FALSE;
Sleep(300);
//close Timer
KillTimer(1001);
//set process at idle
pParent->ProcedureState = STATE_IDLE;
CDialog::OnOK();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -