📄 xugy03dlg.cpp
字号:
BOOL CXugy03Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_OutStopBtn.EnableWindow(FALSE);
m_InStopBtn.EnableWindow(FALSE);
m_LoopStopBtn.EnableWindow(FALSE);
m_MainRead.bInThread = FALSE;
m_MainWrite.bInThread = FALSE;
m_ReadWrite.bInThread = FALSE;
m_MainRead.ulCount = 0;
m_MainWrite.ulCount = 0;
m_ReadWrite.ulCount = 0;
m_GenericOut.bInThread = FALSE;
SetTimer (1, 1000, 0);
m_InterruptIn.testDlg = this;
m_InterruptIn.uiLength = 16;
strcpy(m_InterruptIn.pipe_name,(LPCSTR)"PIPE00");
strcpy(m_InterruptIn.driver_name,(LPCSTR)"D12TEST-0");
CWinThread * wt =AfxBeginThread(
InterruptIn,
&m_InterruptIn);
m_InterruptIn.hThread = wt->m_hThread;
return TRUE; // return TRUE unless you set the focus to a control
}
void CXugy03Dlg::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 CXugy03Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CXugy03Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CXugy03Dlg::OnOutStart()
{
// ::MessageBox(NULL, TEXT("this is CXugy03Dlg::OnOutStart "), "notice:", 0);
m_OutStartBtn.EnableWindow(FALSE);
m_OutStopBtn.EnableWindow(TRUE);
if(m_MainWrite.bInThread)
{
return;
}
m_OutTotalBytes = _T("");
m_OutCurSpeed = _T("");
m_OutAverageSpeed = _T("");
m_OutMaxSpeed = _T("");
UpdateData(FALSE);
m_MainWrite.testDlg = this;
m_MainWrite.uiLength = atoi((LPCSTR)m_OutBufferSize);
strcpy(m_MainWrite.pipe_name, (LPCSTR)"PIPE03");
strcpy(m_MainWrite.driver_name, (LPCSTR)"D12TEST-0");
CWinThread * wt =AfxBeginThread(
WritePipe,
&m_MainWrite);
m_MainWrite.hThread = wt->m_hThread;
}
void CXugy03Dlg::OnOutStop()
{
// ::MessageBox(NULL, "this CXugy03Dlg::OnOutStop ", "notice:", 0);
// m_OutStartBtn.EnableWindow(TRUE);
// m_OutStopBtn.EnableWindow(FALSE);
m_MainWrite.bInThread = FALSE;
}
void CXugy03Dlg::OnInStart()
{
// ::MessageBox(NULL, "this is CXugy03Dlg::OnInStart ", "notice:", MB_OK);
if(m_MainRead.bInThread)
{
return;
}
m_InStartBtn.EnableWindow(FALSE);
m_InStopBtn.EnableWindow(TRUE);
m_InTotalBytes = _T("");
m_InCurSpeed = _T("");
m_InAverageSpeed = _T("");
m_InMaxSpeed = _T("");
UpdateData(FALSE);
m_MainRead.testDlg = this;
m_MainRead.uiLength = atoi ((LPCSTR)m_InBufferSize);
strcpy(m_MainRead.pipe_name,"PIPE02");
strcpy(m_MainRead.driver_name,"D12TEST-0");
CWinThread * wt =AfxBeginThread(
ReadPipe,
&m_MainRead);
m_MainRead.hThread = wt->m_hThread;
}
void CXugy03Dlg::OnInStop()
{
// ::MessageBox(NULL, "this CXugy03Dlg::OnInStop ", "notice:", MB_OK);
// m_InStartBtn.EnableWindow(TRUE);
// m_InStopBtn.EnableWindow(FALSE);
m_MainRead.bInThread = FALSE;
}
void CXugy03Dlg::OnOutBufferSize()
{
// ::MessageBox(NULL, "this is CXugy03Dlg::OnOutBufferSize", "notice:", 0);
UpdateData(TRUE);
}
void CXugy03Dlg::OnInBufferSize()
{
// ::MessageBox(NULL, "this is CXugy03Dlg::OnInBufferSize", "notice:", 0);
UpdateData(TRUE);
}
void CXugy03Dlg::OnTimer(UINT nIDEvent) //定时刷屏
{
char cc[40];
BOOL bUpdate = FALSE;
UpdateData(TRUE);
if(m_MainWrite.bUpdate && (m_MainWrite.ulCount != 0))
{
m_MainWrite.bUpdate = FALSE;
sprintf(cc, "%.3fM bytes",
(float)m_MainWrite.ulCount/1000000.0);
m_OutTotalBytes = cc;
sprintf(cc, "%.1fK bytes",
(float)m_MainWrite.cur_rate/1000.0);
m_OutCurSpeed = cc;
sprintf(cc, "%.1fK bytes",
(float)m_MainWrite.ulCount/m_MainWrite.total_time);
m_OutAverageSpeed = cc;
sprintf(cc, "%.1fK bytes",
(float)m_MainWrite.max_rate/1000.0);
m_OutMaxSpeed = cc;
bUpdate = TRUE;
}
if(m_MainRead.bUpdate && (m_MainRead.ulCount != 0))
{
// Beep(12000,500);
m_MainRead.bUpdate = FALSE;
// sprintf(cc, "%d 字节", m_MainRead.ulCount);
sprintf(cc, "%.3fM bytes",
(float)m_MainRead.ulCount/1000000.0);
m_InTotalBytes = cc;
sprintf(cc, "%.1fk 字节/秒",
(float)m_MainRead.cur_rate/1000.0);
m_InCurSpeed = cc;
sprintf(cc, "%.1fk 字节/秒",
(float)m_MainRead.ulCount/ m_MainRead.total_time);
m_InAverageSpeed = cc;
sprintf(cc, "%.1fk 字节/秒",
(float)m_MainRead.max_rate/1000.0);
m_InMaxSpeed = cc;
bUpdate = TRUE;
}
if(m_ReadWrite.bUpdate && (m_ReadWrite.ulCount != 0))
{
m_ReadWrite.bUpdate = FALSE;
ltoa(m_ReadWrite.ulData[0], cc, 10);
m_PassCount = cc;
ltoa(m_ReadWrite.ulData[1], cc, 10);
m_FailCount = cc;
sprintf(cc, "%.3fM bytes",
(float)m_ReadWrite.ulCount/1000000.0);
// sprintf(cc, "%d bytes",
// m_ReadWrite.ulCount);
m_LoopTotalBytes = cc;
bUpdate = TRUE;
}
if(m_InterruptIn.bUpdate)
{
m_InterruptIn.bUpdate = FALSE;
if(m_InterruptIn.ulData[0] & D12_DRIVERUNLOAD)
{
m_InterruptIn.ulData[0] &= (!D12_DRIVERUNLOAD);
m_KeyStatus = _T("");
SetWindowText("没找到接口设备");
bUpdate = TRUE;
}
if(m_InterruptIn.ulData[0] & D12_DRIVERLOAD)
{
m_InterruptIn.ulData[0] &= (!D12_DRIVERLOAD);
switch(m_InterruptIn.ulData[1] &0xf0)
{
case 0:
SetWindowText("D12 评估板");
m_ctrlLED3.EnableWindow(TRUE);
m_ctrlLED4.EnableWindow(TRUE);
break;
case 0x10:
SetWindowText("D12 评估板-8052型");
m_ctrlLED3.EnableWindow(TRUE);
m_ctrlLED4.EnableWindow(TRUE);
break;
case 0x20:
SetWindowText("D12 USB_EPP评估板");
m_ctrlLED3.EnableWindow(FALSE);
m_ctrlLED4.EnableWindow(FALSE);
break;
default:
SetWindowText("89C52-D12测试板");
break;
}
bUpdate = TRUE;
}
if(m_InterruptIn.ulData[0] & D12_KEYSTATUS)
{
m_InterruptIn.ulData[0] &= (!D12_KEYSTATUS);
Beep(5000,50);
if(!m_InterruptIn.ulData[2])
m_KeyStatus = _T("按键已按下");
else
m_KeyStatus = _T("按键已释放");
bUpdate = TRUE;
}
}
if(bUpdate)
UpdateData(FALSE);
CDialog::OnTimer(nIDEvent);
}
BOOL CXugy03Dlg::DestroyWindow()
{
// ::MessageBox(NULL, "this is CXugy03Dlg::DestroyWindow", "notice:", 0);
KillTimer(1);
return CDialog::DestroyWindow();
}
void CXugy03Dlg::OnLoopStart()
{
// ::MessageBox(NULL, "this is CXugy03Dlg::OnLoopStart", "notice:", 0);
if (m_ReadWrite.bInThread
||m_MainRead.bInThread
||m_MainWrite.bInThread)
{
return;
}
m_LoopStartBtn.EnableWindow(FALSE);
m_LoopStopBtn.EnableWindow(TRUE);
m_PassCount = _T("");
m_FailCount = _T("");
m_LoopTotalBytes = _T("");
UpdateData(FALSE);
m_ReadWrite.testDlg = this;
m_ReadWrite.uiLength = atoi((LPCSTR)m_LoopBufSize);
m_ReadWrite.ulData[2] = atol((LPCSTR)m_LoopRepeatTimes);
strcpy(m_ReadWrite.pipe_name,(LPCSTR)"PIPE02");
strcpy(m_ReadWrite.driver_name,(LPCSTR)"D12TEST-0");
CWinThread * wt = AfxBeginThread(ReadWrite,
&m_ReadWrite);
m_ReadWrite.hThread = wt->m_hThread;
}
void CXugy03Dlg::OnLoopStop()
{
// ::MessageBox(NULL, "this is CXugy03Dlg::OnLoopStop", "notice:", 0);
m_ReadWrite.bInThread = FALSE;
}
void CXugy03Dlg::OnLoopBufSize()
{
// ::MessageBox(NULL, "this is CXugy03Dlg::OnLoopBufSize", "notice:", 0);
UpdateData(TRUE);
}
void CXugy03Dlg::OnLED1()
{
// ::MessageBox(NULL, "this is CXugy03Dlg::OnLED1", "notice:", 0);
UpdateData(TRUE);
ChangeLED();
}
void CXugy03Dlg::OnLED2()
{
// ::MessageBox(NULL, "this is CXugy03Dlg::OnLED2", "notice:", 0);
UpdateData(TRUE);
ChangeLED();
}
void CXugy03Dlg::OnLED3()
{
// ::MessageBox(NULL, "this is CXugy03Dlg::OnLED3", "notice:", 0);
UpdateData(TRUE);
ChangeLED();
}
void CXugy03Dlg::OnLED4()
{
// ::MessageBox(NULL, "this is CXugy03Dlg::OnLED4", "notice:", 0);
UpdateData(TRUE);
ChangeLED();
}
void CXugy03Dlg::ChangeLED()
{
unsigned char *data_buf;
if(m_GenericOut.bInThread)
{
return;
}
data_buf = (unsigned char *) malloc(16);
if(data_buf == NULL)
{
::MessageBox(NULL,"内存不够", "CXugy03Dlg::ChangeLED:", MB_ICONSTOP);
EndDialog(0);
return ;
}
memset (data_buf, 0, 16);
if(m_LED1)
*(data_buf+3) |= 0x1;
if(m_LED2)
*(data_buf+3) |= 0x2;
if(m_LED3)
*(data_buf+3) |= 0x4;
if(m_LED4)
*(data_buf+3) |= 0x8;
m_GenericOut.testDlg = this;
m_GenericOut.uiLength = 4;
m_GenericOut.pcIoBuffer = data_buf;
strcpy(m_GenericOut.pipe_name, (LPCSTR)"PIPE01");
strcpy(m_GenericOut.driver_name,(LPCSTR)"D12TEST-0");
CWinThread *wt = AfxBeginThread(
GenericOut,
&m_GenericOut);
m_GenericOut.hThread = wt->m_hThread;
// free(data_buf);
// data_buf = NULL;
// ::MessageBox(NULL, "this is CXugy03Dlg::ChangeLED", "notice:", 0);
}
void CXugy03Dlg::OnLoopRepeatTimes()
{
// ::MessageBox(NULL, "this is CXugy03Dlg::OnLoopRepeatTimes", "notice:", 0);
UpdateData(TRUE);
}
void CXugy03Dlg::OnOk()
{
::MessageBox(NULL, "this is CXugy03Dlg::OnOk", "notice:", 0);
}
void CXugy03Dlg::OnCancel()
{
if((!m_ReadWrite.bInThread)
&&(!m_MainRead.bInThread)
&&(!m_MainWrite.bInThread))
{
EndDialog(0);
}
else
{
m_KillDialog.tp[0] = &m_ReadWrite;
m_KillDialog.tp[1] = &m_MainWrite;
m_KillDialog.tp[2] = &m_MainRead;
m_KillDialog.testDlg = this;
AfxBeginThread(KillDialog,
&m_KillDialog);
}
if((!m_ReadWrite.bInThread)
&&(!m_MainRead.bInThread)
&&(!m_MainWrite.bInThread))
{
EndDialog(0);
}
else
{
m_KillDialog.tp[0] = &m_ReadWrite;
m_KillDialog.tp[1] = &m_MainWrite;
m_KillDialog.tp[2] = &m_MainRead;
m_KillDialog.testDlg = this;
AfxBeginThread(KillDialog,
&m_KillDialog);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -