📄 testdlg.cpp
字号:
TestDlg->m_nTestPass=TestPass;
ThreadParam->bUpdate=TRUE;
}//end while(gstoptest)
TestDlg->m_nError=Errors;
TestDlg->m_nTestPass=TestPass;
free(inBuffer);
free(outBuffer);
CloseHandle(hInDevice);
CloseHandle(hOutDevice);
ThreadParam->bUpdate=TRUE;
return 0;
}
/////////////////////////////////////////////////////////////////////////////
// CTestDlg dialog
CTestDlg::CTestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTestDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTestDlg)
m_strName = _T("");
m_strOutput = _T("");
m_nSize = 0;
m_nTestPass = 0;
m_nError = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTestDlg)
DDX_Control(pDX, IDC_BTNSTOP, m_btnStop);
DDX_Control(pDX, IDC_BTNSTART, m_btnStart);
DDX_Text(pDX, IDC_EDTNAME, m_strName);
DDX_Text(pDX, IDC_EDTOUTPUT, m_strOutput);
DDX_Text(pDX, IDC_EDTSIZE, m_nSize);
DDX_Text(pDX, IDC_EDTPASS, m_nTestPass);
DDX_Text(pDX, IDC_EDTERROR, m_nError);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
//{{AFX_MSG_MAP(CTestDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BTNLIST, OnBtnlist)
ON_BN_CLICKED(IDC_BTNCLEAR, OnBtnclear)
ON_BN_CLICKED(IDC_BTNSTOP, OnBtnstop)
ON_BN_CLICKED(IDC_BTNSTART, OnBtnstart)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_BTNSPEED, OnBtnspeed)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestDlg message handlers
BOOL CTestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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_strName = _T("EZUSB-0");
m_strOutput = _T("");
m_nSize =60000;
HANDLE hDevice;//设备句柄
UpdateData(FALSE);
if(!bOpenDriver(&hDevice,m_strName.GetBuffer(m_strName.GetLength())))
{
m_strOutput+="打开设备失败,请检查设备名是正确\r\n";
}
else
{
m_strOutput+="打开设备成功\r\n";
}
CloseHandle(hDevice);
m_btnStart.EnableWindow(FALSE);
m_btnStop.EnableWindow(FALSE);
gStopTest=FALSE;
SetTimer(1, 1000, 0);
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
}
// 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 CTestDlg::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 CTestDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CTestDlg::OnBtnlist()
{
HANDLE hDevice = NULL;
ULONG nBytes;
char tempbuff[256];
PUSBD_INTERFACE_INFORMATION pInterfaceInfo;
PUSBD_PIPE_INFORMATION pPipeInfo;
ULONG i;
UCHAR gInterfaceInfo [1024];
UpdateData(FALSE);
if(!bOpenDriver(&hDevice,m_strName.GetBuffer(m_strName.GetLength())))
{
m_strOutput+="打开设备失败,请检查设备名是正确\r\n";
}
DeviceIoControl (hDevice,
IOCTL_Ezusb_GET_PIPE_INFO,
NULL,
0,
&gInterfaceInfo,
sizeof(gInterfaceInfo),
&nBytes,
NULL);
CloseHandle(hDevice);
pInterfaceInfo = (PUSBD_INTERFACE_INFORMATION) &gInterfaceInfo;
m_strOutput+="Pipe Endpoint Direction Type Size\r\n";
for (i=0;i<pInterfaceInfo->NumberOfPipes;i++)
{
pPipeInfo = &pInterfaceInfo->Pipes[i];
sprintf(tempbuff,"%2d %2d %s %s %4d",
i,
pPipeInfo->EndpointAddress & 0x0F,
pPipeInfo->EndpointAddress & 0x80 ? "IN " : "OUT",
PIPE_TYPE_STRINGS[pPipeInfo->PipeType],
pPipeInfo->MaximumPacketSize);
m_strOutput+=tempbuff;
m_strOutput+="\r\n";
}
UpdateData(FALSE);
}
void CTestDlg::OnBtnclear()
{
m_strOutput="";
UpdateData(FALSE);
}
void CTestDlg::OnBtnstop()
{
m_btnStart.EnableWindow(TRUE);
m_btnStop.EnableWindow(FALSE);
gStopTest=TRUE;
}
void CTestDlg::OnBtnstart()
{
UpdateData(TRUE);
gStopTest=FALSE;
m_BulkTest.testDlg=this;
m_BulkTest.bUpdate=FALSE;
CWinThread * wt = AfxBeginThread(
TestThread, // thread function
&m_BulkTest); // argument to thread function
m_BulkTest.hThread = wt->m_hThread;
m_btnStart.EnableWindow(FALSE);
m_btnStop.EnableWindow(TRUE);
UpdateData(FALSE);
}
void CTestDlg::OnTimer(UINT nIDEvent)
{
if(m_BulkTest.bUpdate)
{
m_BulkTest.bUpdate=FALSE;
UpdateData(FALSE);
}
CDialog::OnTimer(nIDEvent);
}
void CTestDlg::OnBtnspeed()
{
UpdateData(TRUE);
PUCHAR outBuffer = NULL;
unsigned long mstep,mlength;
double speed;
BULK_TRANSFER_CONTROL outBulkControl;//inBulkControl,
THREAD_CONTROL outThreadControl;//inThreadControl,
HANDLE hOutDevice=NULL,hInDevice=NULL;
ULONG OutPipeNum;//,InPipeNum
char output[256];
double mTotal;
if (bOpenDriver (&hOutDevice, m_strName.GetBuffer(m_strName.GetLength())) != TRUE)
{
m_strOutput+="打开设备失败\r\n";
UpdateData(FALSE);
return ;
}
outBuffer=(PUCHAR) malloc(m_nSize);
srand(m_nSize);
for(ULONG i=0;i<m_nSize;i++)
outBuffer[i]=rand();
BOOLEAN status=FALSE;
ULONG BytesReturned=0;
ULONG nTestCount=100;//共循环测试100次
outBulkControl.pipeNum=0;//端点选择EP2
mstep=GetTickCount(); //起始时间
for( i=0;i<nTestCount;i++)//多次循环测试
{
status = DeviceIoControl (hOutDevice,
IOCTL_EZUSB_BULK_WRITE,
(PVOID)&outBulkControl,
sizeof(BULK_TRANSFER_CONTROL),
outBuffer,//输出缓冲区
m_nSize,//字节数,在对话框中可以设置,60000为较佳值
&BytesReturned,//返回字节数据
//这里为了测试速度,没有测试返回字节数
NULL);
}
mlength=GetTickCount();//结束时间
if(status==TRUE)
{
mTotal=m_nSize*nTestCount;
m_strOutput+="测试成功\r\n";
mlength-=mstep;
if ( mlength !=0 ) speed=mTotal/mlength;
else speed=9999999;
sprintf( output,"***speed = %10.2f KBytes/Sec, total=%10.2f bytes, time=%ld mS\r\n", speed, mTotal, mlength);
m_strOutput+=output;
}
else
{
m_strOutput+="测试失败\r\n";
}
//关闭设备
free(outBuffer);
CloseHandle(hOutDevice);
UpdateData(FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -