PIC Vietnam

Go Back   PIC Vietnam > Truyền thông > Giao tiếp USB, CAN, I2C, SPI, USART...

Tài trợ cho PIC Vietnam
Trang chủ Đăng Kí Hỏi/Ðáp Thành Viên Lịch Bài Trong Ngày Vi điều khiển

Giao tiếp USB, CAN, I2C, SPI, USART... Những giao tiếp được tích hợp trên PIC

 
 
Ðiều Chỉnh Xếp Bài
Prev Previous Post   Next Post Next
Old 14-12-2006, 12:27 PM   #14
hungbkhn
Trưởng lão PIC bang
 
Tham gia ngày: Jun 2006
Bài gửi: 39
:
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.
hungbkhn vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
 


Quyền Sử Dụng Ở Diễn Ðàn
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Mở
Smilies đang Mở
[IMG] đang Mở
HTML đang Tắt

Chuyển đến


Múi giờ GMT. Hiện tại là 08:07 PM.


Được sáng lập bởi Đoàn Hiệp
Powered by vBulletin®
Page copy protected against web site content infringement by Copyscape
Copyright © PIC Vietnam