📄 d12testdlg.cpp
字号:
{
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_MainRead.hThread=NULL;
m_MainWrite.bInThread = FALSE;
m_MainWrite.hThread=NULL;
m_ReadWrite.bInThread = FALSE;
m_ReadWrite.hThread=NULL;
m_MainRead.ulCount = 0;
m_MainWrite.ulCount = 0;
m_ReadWrite.ulCount = 0;
SetTimer(1, 500, 0);
m_InterruptIn.testDlg = this;
m_InterruptIn.uiLength = 16;
strcpy(m_InterruptIn.pipe_name, (LPCSTR)"PIPE00");
strcpy(m_InterruptIn.driver_name, (LPCSTR)"D12TEST-0");
m_InterruptIn.bInThread=true;
m_InterruptIn.threadFile1=NULL;
m_InterruptIn.threadFile2=NULL;
CWinThread * wt = AfxBeginThread(
InterruptIn, // thread function
&m_InterruptIn); // argument to thread function
m_InterruptIn.hThread = wt;
return TRUE; // return TRUE unless you set the focus to a control
}
void CD12TestDlg::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 CD12TestDlg::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 CD12TestDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CD12TestDlg::OnOutStart()
{
// TODO: Add your control notification handler code here
if( m_MainWrite.bInThread == TRUE)
{
return;
}
m_OutTotalBytes = _T("");
m_OutCurSpeed = _T("");
m_OutAverageSpeed = _T("");
m_OutMaxSpeed = _T("");
UpdateData(FALSE);
m_MainWrite.testDlg = this;
m_MainWrite.uiLength = m_OutSize;
strcpy(m_MainWrite.pipe_name, (LPCSTR)"PIPE03");
strcpy(m_MainWrite.driver_name, (LPCSTR)"D12TEST-0");
m_MainWrite.threadFile1=NULL;
m_MainWrite.threadFile2=NULL;
CWinThread * wt = AfxBeginThread(
WritePipe, // thread function
&m_MainWrite); // argument to thread function
m_MainWrite.hThread = wt;
}
void CD12TestDlg::OnOutStop()
{
// TODO: Add your control notification handler code here
m_MainWrite.bInThread = FALSE;
}
void CD12TestDlg::OnInStart()
{
// TODO: Add your control notification handler code here
if( m_MainRead.bInThread == TRUE) {
return;
}
m_InTotalBytes = _T("");
m_InCurSpeed = _T("");
m_InAverageSpeed = _T("");
m_InMaxSpeed = _T("");
UpdateData(FALSE);
m_MainRead.testDlg = this;
m_MainRead.uiLength = m_InSize;
strcpy(m_MainRead.pipe_name, (LPCSTR)"PIPE02");
strcpy(m_MainRead.driver_name, (LPCSTR)"D12TEST-0");
m_MainRead.threadFile1=NULL;
m_MainRead.threadFile2=NULL;
CWinThread * wt = AfxBeginThread(
ReadPipe, // thread function
&m_MainRead); // argument to thread function
m_MainRead.hThread = wt;
}
void CD12TestDlg::OnInStop()
{
// TODO: Add your control notification handler code here
m_MainRead.bInThread = FALSE;
}
void CD12TestDlg::OnOutBufferSize()
{
// TODO: Add your control notification handler code here
int temp=m_OutSize;//暂时保留原来的页码值
if (!UpdateData(true)) {
m_OutSize=temp;
UpdateData(false);
}
}
void CD12TestDlg::OnInBufferSize()
{
// TODO: Add your control notification handler code here
int temp=m_InSize;//暂时保留原来的页码值
if (!UpdateData(true)) {
m_InSize=temp;
UpdateData(false);
}
}
void CD12TestDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
char cc[40];
BOOL bUpdate = FALSE;
if( m_MainWrite.bUpdate == TRUE && m_MainWrite.ulCount != 0) {
m_MainWrite.bUpdate = FALSE;
sprintf(cc, "%ld bytes", m_MainWrite.ulCount);
// sprintf(cc, "%.2fM bytes",
// (float)m_MainWrite.ulCount/1000000.0);
m_OutTotalBytes = cc;
sprintf(cc, "%.1fK bytes/s",
(double)m_MainWrite.ulCount/m_MainWrite.total_time);
m_OutAverageSpeed = cc;
sprintf(cc, "%.1fK bytes/s",
(float)(m_MainWrite.cur_rate)/1000.0);
m_OutCurSpeed = cc;
sprintf(cc, "%.1fK bytes/s",
(float)(m_MainWrite.max_rate)/1000.0);
m_OutMaxSpeed = cc;
bUpdate = TRUE;
}
if( m_MainRead.bUpdate == TRUE && m_MainRead.ulCount != 0) {
m_MainRead.bUpdate = FALSE;
sprintf(cc, "%ld bytes", m_MainRead.ulCount);
// sprintf(cc, "%.2fM bytes",
// (float)m_MainRead.ulCount/1000000.0);
m_InTotalBytes = cc;
sprintf(cc, "%.1fK bytes/s",
(double)m_MainRead.ulCount/m_MainRead.total_time);
m_InAverageSpeed = cc;
sprintf(cc, "%.1fK bytes/s",
(float)(m_MainRead.cur_rate)/1000.0);
m_InCurSpeed = cc;
sprintf(cc, "%.1fK bytes/s",
(float)(m_MainRead.max_rate)/1000.0);
m_InMaxSpeed = cc;
bUpdate = TRUE;
}
if( m_ReadWrite.bUpdate == TRUE) {
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, "%.2fM bytes",
(float)m_ReadWrite.ulCount/1000000.0);
m_LoopTotalBytes = cc;
bUpdate = TRUE;
}
if( m_InterruptIn.bUpdate == TRUE) {
m_InterruptIn.bUpdate = FALSE;
if(m_InterruptIn.ulData[0] & D12_DRIVERUNLOAD){
m_InterruptIn.ulData[0] &= (!D12_DRIVERUNLOAD);
m_KeyStatus = _T("");
SetWindowText("PDIUSBD12 Test Application - No Device Attached");
bUpdate = TRUE;
}
if(m_InterruptIn.ulData[0] & D12_DRIVERLOAD){
m_InterruptIn.ulData[0] &= (!D12_DRIVERLOAD);
switch(m_InterruptIn.ulData[1] & 0xf0) {
case 0:
SetWindowText("PDIUSBD12 Evaluation Board");
m_OutSize = 64;
m_InSize = 64;
m_OutTotalBytes = _T("");
m_OutCurSpeed = _T("");
m_OutAverageSpeed = _T("");
m_OutMaxSpeed = _T("");
m_InTotalBytes = _T("");
m_InCurSpeed = _T("");
m_InAverageSpeed = _T("");
m_InMaxSpeed = _T("");
m_KeyStatus = _T("");
m_PassCount = _T("");
m_FailCount = _T("");
m_LoopSize = 64;
m_LED1 = FALSE;
m_LED2 = FALSE;
m_LED3 = FALSE;
m_LED4 = FALSE;
m_LoopTotalBytes = _T("");
m_LoopRepeatTimes = _T("-1");
m_ctrlLED3.EnableWindow(TRUE);
m_ctrlLED4.EnableWindow(TRUE);
break;
case 0x10:
SetWindowText("PDIUSBD12 Evaluation Board - 8052 Daughter Board");
m_OutSize = 64;
m_InSize = 64;
m_OutTotalBytes = _T("");
m_OutCurSpeed = _T("");
m_OutAverageSpeed = _T("");
m_OutMaxSpeed = _T("");
m_InTotalBytes = _T("");
m_InCurSpeed = _T("");
m_InAverageSpeed = _T("");
m_InMaxSpeed = _T("");
m_KeyStatus = _T("");
m_PassCount = _T("");
m_FailCount = _T("");
m_LoopSize = 64;
m_LED1 = FALSE;
m_LED2 = FALSE;
m_LED3 = FALSE;
m_LED4 = FALSE;
m_LoopTotalBytes = _T("");
m_LoopRepeatTimes = _T("-1");
m_ctrlLED3.EnableWindow(TRUE);
m_ctrlLED4.EnableWindow(TRUE);
break;
case 0x20:
SetWindowText("PDIUSBD12 USB-EPP Evaluation Board");
m_OutSize = 64;
m_InSize = 64;
m_OutTotalBytes = _T("");
m_OutCurSpeed = _T("");
m_OutAverageSpeed = _T("");
m_OutMaxSpeed = _T("");
m_InTotalBytes = _T("");
m_InCurSpeed = _T("");
m_InAverageSpeed = _T("");
m_InMaxSpeed = _T("");
m_KeyStatus = _T("");
m_PassCount = _T("");
m_FailCount = _T("");
m_LoopSize = 64;
m_LED1 = FALSE;
m_LED2 = FALSE;
m_LED3 = FALSE;
m_LED4 = FALSE;
m_LoopTotalBytes = _T("");
m_LoopRepeatTimes = _T("-1");
m_ctrlLED3.EnableWindow(FALSE);
m_ctrlLED4.EnableWindow(FALSE);
break;
case 0x30:
SetWindowText("PDIUSBD12 SMART Evaluation Board");
m_OutSize = 64;
m_InSize = 64;
m_OutTotalBytes = _T("");
m_OutCurSpeed = _T("");
m_OutAverageSpeed = _T("");
m_OutMaxSpeed = _T("");
m_InTotalBytes = _T("");
m_InCurSpeed = _T("");
m_InAverageSpeed = _T("");
m_InMaxSpeed = _T("");
m_KeyStatus = _T("");
m_PassCount = _T("");
m_FailCount = _T("");
m_LoopSize = 64;
m_LED1 = FALSE;
m_LED2 = FALSE;
m_LED3 = FALSE;
m_LED4 = FALSE;
m_LoopTotalBytes = _T("");
m_LoopRepeatTimes = _T("-1");
m_ctrlLED3.EnableWindow(FALSE);
m_ctrlLED4.EnableWindow(FALSE);
break;
default:
SetWindowText("Unknown Board");
break;
}
bUpdate = TRUE;
}
}
if( bUpdate )
UpdateData(FALSE);
CDialog::OnTimer(nIDEvent);
}
BOOL CD12TestDlg::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
KillTimer(1);
return CDialog::DestroyWindow();
}
void CD12TestDlg::OnLoopStart()
{
// TODO: Add your control notification handler code here
if( m_ReadWrite.bInThread == TRUE
|| m_MainWrite.bInThread == TRUE
|| m_MainRead.bInThread == TRUE )
{
return;
}
m_PassCount = _T("");
m_FailCount = _T("");
m_LoopTotalBytes = _T("");
UpdateData(FALSE);
m_ReadWrite.testDlg = this;
m_ReadWrite.uiLength = m_LoopSize;
m_ReadWrite.ulData[2] = atol((LPCSTR)m_LoopRepeatTimes);
strcpy(m_ReadWrite.pipe_name, (LPCSTR)"PIPE02");
strcpy(m_ReadWrite.driver_name, (LPCSTR)"D12TEST-0");
m_ReadWrite.threadFile1=NULL;
m_ReadWrite.threadFile2=NULL;
CWinThread * wt = AfxBeginThread(
ReadWrite, // thread function
&m_ReadWrite); // argument to thread function
m_ReadWrite.hThread = wt;
}
void CD12TestDlg::OnLoopStop()
{
// TODO: Add your control notification handler code here
m_ReadWrite.bInThread = FALSE;
}
void CD12TestDlg::OnLoopBufSize()
{
// TODO: Add your control notification handler code here
int temp=m_LoopSize;
if (!UpdateData(true)) {
m_LoopSize=temp;
UpdateData(false);
}
}
void CD12TestDlg::OnLED1()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
ChangeLED();
}
void CD12TestDlg::OnLED2()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
ChangeLED();
}
void CD12TestDlg::OnLED3()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
ChangeLED();
}
void CD12TestDlg::OnLED4()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
ChangeLED();
}
void CD12TestDlg::ChangeLED()
{
unsigned char * data_buf;
if( m_GenericOut.bInThread == TRUE) {
return;
}
data_buf = (unsigned char *)malloc(16);
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");
m_GenericOut.threadFile1=NULL;
m_GenericOut.threadFile2=NULL;
CWinThread * wt = AfxBeginThread(
GenericOut, // thread function
&m_GenericOut); // argument to thread function
m_GenericOut.hThread = wt;
}
void CD12TestDlg::OnLoopRepeatTimes()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
}
void CD12TestDlg::OnOK()
{
}
void CD12TestDlg::OnCancel()
{
if(m_ReadWrite.bInThread==TRUE) {
if (m_ReadWrite.threadFile1!=NULL) {
free(ReadWriteBuff);
}
if (m_ReadWrite.threadFile2!=NULL) {
free(m_ReadWrite.pcIoBuffer);
}
delete m_ReadWrite.hThread;
}
if(m_MainWrite.bInThread==TRUE) {
if (m_MainWrite.threadFile1!=NULL) {
free(m_MainWrite.pcIoBuffer);
}
delete m_MainWrite.hThread;
}
if(m_MainRead.bInThread==TRUE) {
if (m_MainRead.threadFile1!=NULL) {
free(m_MainRead.pcIoBuffer);
}
delete m_MainRead.hThread;
}
if(m_InterruptIn.bInThread==TRUE) {
free(m_InterruptIn.pcIoBuffer);
delete m_InterruptIn.hThread;
}
CDialog::OnCancel();
}
LRESULT CD12TestDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
if (message==0x405)
UpdateData(false);
return CDialog::WindowProc(message, wParam, lParam);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -