void CCYDEMODlg::OnButtonWrSpeedtest()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
PUCHAR outBuffer = NULL;
unsigned long mstep,mlength;
double speed;
BULK_TRANSFER_CONTROL outBulkControl;//inBulkControl,
HANDLE hOutDevice=NULL;
char output[256];
double mTotal;
if (!OnSetOutDir())
{
free(outBuffer);
CloseHandle(hOutDevice);
return ;
}
if (bOpenDriver (&hOutDevice, m_strName.GetBuffer(m_strName.GetLength())) != TRUE)
{
CloseHandle(hOutDevice);
return ;
}
outBuffer=(PUCHAR) malloc(m_TestBytes);
srand(m_TestBytes);
for(ULONG i=0;i<m_TestBytes;i++)
outBuffer[i]=rand();
BOOLEAN status=FALSE;
ULONG BytesReturned=0;
ULONG nTestCount=1000;//¹²Ñ»·²âÊÔ1000´Î
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_TestBytes,//×Ö½ÚÊý£¬ÔÚ¶Ô»°¿òÖпÉÒÔÉèÖã¬65535Ϊ½Ï¼ÑÖµ
&BytesReturned,//·µ»Ø×Ö½ÚÊý¾Ý
//ÕâÀïΪÁ˲âÊÔËٶȣ¬Ã»ÓвâÊÔ·µ»Ø×Ö½ÚÊý
NULL);
}
mlength=GetTickCount();//½áÊøʱ¼ä
if(status==TRUE)
{
mTotal=m_TestBytes * nTestCount;
mlength-=mstep;
if ( mlength !=0 ) speed=(mTotal/mlength)/1000.0;
else speed=9999999;
sprintf( output,
"дÊý¾ÝËÙ¶ÈΪ£º%3.3f MBytes/Sec/r/n¹²´«Ê䣺%d¡Á%d=%10.2f×Ö½Ú/r/nºÄʱ£º%ldmS/r/n",
speed,m_TestBytes, nTestCount,mTotal, mlength);
m_strTestDisplay=output;
}
else
{
m_strTestDisplay="²âÊÔʧ°Ü£¡/r/n";
}
//¹Ø±ÕÉ豸
free(outBuffer);
CloseHandle(hOutDevice);
UpdateData(FALSE);
}
void CCYDEMODlg::OnButtonRdSpeedtest()
{
// TODO: Add your control notification handler code here
CFile file;
CFileException e;
file.Open("E://error.txt", CFile::modeWrite, &e );
int i;
UpdateData(TRUE);
PUCHAR outBuffer = NULL;
unsigned long mstep,mlength;
double speed;
int nTestCount=100;//¹²Ñ»·²âÊÔ100´Î
BULK_TRANSFER_CONTROL inBulkControl;//,outBulkControl
THREAD_CONTROL inThreadControl;//,outThreadControl
HANDLE hOutDevice=NULL;
HANDLE ReadCompleteEvent;
// ReadCompleteEvent = CreateEvent(0,FALSE,FALSE,NULL);
char output[256];
double mTotal;
if (!OnSetInDir())
{
free(outBuffer);
CloseHandle(hOutDevice);
return ;
}
if (bOpenDriver (&hOutDevice, m_strName.GetBuffer(m_strName.GetLength())) != TRUE)
{
CloseHandle(hOutDevice);
return ;
}
outBuffer=(unsigned char*)malloc(nTestCount*512*127);
inBulkControl.pipeNum=1; //¶ËµãÑ¡ÔñEP6
inThreadControl.hDevice=hOutDevice;
inThreadControl.Ioctl=IOCTL_EZUSB_BULK_READ;
inThreadControl.InBuffer=(void*)&inBulkControl;
inThreadControl.InBufferSize=sizeof(BULK_TRANSFER_CONTROL);
inThreadControl.OutBuffer=outBuffer;
inThreadControl.OutBufferSize= 512*127;
inThreadControl.status=FALSE;
inThreadControl.BytesReturned=0;
inThreadControl.completionEvent=ReadCompleteEvent;
DWORD s;
mstep=GetTickCount(); //Æðʼʱ¼ä
for( i=0;i<nTestCount;i++)//¶à´ÎÑ»·²âÊÔ
{
inThreadControl.OutBuffer=outBuffer+i*512*127;
WaitForSingleObject( CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)TransferThread, (LPVOID)&inThreadControl,(DWORD)0,&s),INFINITE);
}
mlength=GetTickCount();//½áÊøʱ¼ä
file.Write(outBuffer,nTestCount*512*127);
if(inThreadControl.status)
{
mTotal=nTestCount*512*127;
mlength-=mstep;
if ( mlength !=0 ) speed=(mTotal/mlength)/1000.0;
else speed=9999999;
sprintf( output,
"¶ÁÊý¾ÝËÙ¶ÈΪ£º%3.3f MBytes/Sec/r/n¹²´«Ê䣺%10.2f×Ö½Ú/r/nºÄʱ£º%ldmS/r/n",
speed, mTotal, mlength);
m_strTestDisplay=output;
}
else
{
m_strTestDisplay="²âÊÔʧ°Ü/r/n";
}
//¹Ø±ÕÉ豸
file.Close();
free(outBuffer);
CloseHandle(hOutDevice);
UpdateData(FALSE);
}