Tôi phân tích tiếp xem thế nào nhé

.
Cái ví dụ của microchip dùng trễ 100ms
MPUSBRead(myInPipe,ReceiveData,ExpectedReceiveLeng th,ReceiveLength,100);
bây giờ dịch tìm cái nguồn của hàm này, buộc dịch lại dll.
trong file nguồn ta thấy:
///////////////////////////////////////////////////////////////////////////////
// MPUSBRead :
//
// handle - Identifies the endpoint pipe to be read. The pipe handle must
// have been created with MP_READ access attribute.
//
// pData - Points to the buffer that receives the data read from the pipe.
//
// dwLen - Specifies the number of bytes to be read from the pipe.
//
// pLength - Points to the number of bytes read. MPUSBRead sets this value to
// zero before doing any work or error checking.
//
// dwMilliseconds
// - Specifies the time-out interval, in milliseconds. The function
// returns if the interval elapses, even if the operation is
// incomplete. If dwMilliseconds is zero, the function tests the
// data pipe and returns immediately. If dwMilliseconds is INFINITE,
// the function's time-out interval never elapses.
//
// Note that "input" and "output" refer to the parameter designations in calls
// to this function, which are the opposite of common sense from the
// perspective of an application making the calls.
//
DWORD MPUSBRead(HANDLE handle, // Input
PVOID pData, // Output
DWORD dwLen, // Input
PDWORD pLength, // Output
DWORD dwMilliseconds) // Input
{
BOOL bResult;
DWORD nBytesRead;
OVERLAPPED gOverlapped;
DWORD dwResult;
dwResult = MPUSB_FAIL;
// set up overlapped structure fields
gOverlapped.Internal = 0;
gOverlapped.InternalHigh = 0;
gOverlapped.Offset = 0;
gOverlapped.OffsetHigh = 0;
gOverlapped.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
if(pLength != NULL)*pLength = 0;
// attempt an asynchronous read operation
bResult = ReadFile(handle,pData,dwLen,&nBytesRead,&gOverlapp ed);
if(!bResult)
{
// deal with the error code
switch (GetLastError())
{
case ERROR_HANDLE_EOF:
{
// we have reached the end of the file
// during the call to ReadFile
break;
}
case ERROR_IO_PENDING:
{
// asynchronous i/o is still in progress
switch(WaitForSingleObject(gOverlapped.hEvent, dwMilliseconds))
...
tôi trích đến đây vì thấy hàm WaitForSingleObject(...).
Tham khảo link sau để thấy nó làm gì
http://msdn.microsoft.com/library/de...ngleobject.asp
như vậy ta có thể thử với biến dwMilliseconds,
Các bạn tiếp tục xem thế nào.