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

Trả lời
 
Ðiều Chỉnh Xếp Bài
Old 13-12-2006, 01:04 PM   #1
ntc
Đệ tử 8 túi
 
ntc's Avatar
 
Tham gia ngày: Oct 2005
Nơi Cư Ngụ: HCM city
Bài gửi: 264
:
Send a message via Yahoo to ntc
Trong cái ví dụ sử dụng thư viện dll, người ta xây dựng theo kiểu truyền đi, xong chờ nhận lại kết quả, rồi mới tính tiếp, mỗi lần truyền nhận như vậy delay tới 1s, do đó không thể nhanh được.

Bạn thử hạ thời gian delay xem thế nào, xem thử hạ tới đâu thì vẫn còn hoạt động tốt, xong rồi thông báo kết quả lên đây, để anh em thảo luận thêm.

Làm theo vi dụ này, có thể tạm ứng dụng trong điều khiển với dung lượng dữ liệu cần truyền nhận nhỏ.
__________________

ntc vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 14-12-2006, 10:10 AM   #2
phamthaihoa
Đệ tử 3 túi
 
Tham gia ngày: Jun 2005
Bài gửi: 56
:
Trích:
Nguyên văn bởi ntc View Post
Trong cái ví dụ sử dụng thư viện dll, người ta xây dựng theo kiểu truyền đi, xong chờ nhận lại kết quả, rồi mới tính tiếp, mỗi lần truyền nhận như vậy delay tới 1s, do đó không thể nhanh được.

Bạn thử hạ thời gian delay xem thế nào, xem thử hạ tới đâu thì vẫn còn hoạt động tốt, xong rồi thông báo kết quả lên đây, để anh em thảo luận thêm.

Làm theo vi dụ này, có thể tạm ứng dụng trong điều khiển với dung lượng dữ liệu cần truyền nhận nhỏ.
Hạ thời gian xuống không có tác dụng, thế mới đểu chứ

Em thử hạ thời gian xuống, cỡ trên 10ms thì ổn định. Còn nếu <10ms thì lỗi độ dài dữ liệu nhân được < độ dài được chỉ định.
phamthaihoa vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 14-12-2006, 12:27 PM   #3
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
Trả lời


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à 02:52 AM.


Đượ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