阅读:1254回复:4
为什么不能对USB端口读写数据
我用DS2.5 生成的USB驱动程序,在编译通过后,不能对endpoint2读写,我用仿真器跟踪单片机程序发现,对endpoint2读时,第一次发读命令时,单片机程序中endpoint2口有反映,但以后就没有反映了,但单片机程序复位后,又能反映一次。有发现对endpoint2写时,单片机程序中endpoint2口都有反映,但USB驱动程序监测到的是写不成功,别人提供的USB驱动程序,对endpoint2读写都是正常的。是不是从驱动开发网上下的DS2.5有使用上的问题,请高手指点!
谢谢! 以下读操作程序是有DS2.5自动生成的: NTSTATUS ZboarduDevice::Read(KIrp I) { t << \"Entering ZboarduDevice::Read, \" << I << EOL; // TODO: Check the incoming request. Replace \"FALSE\" in the following // line with a check that returns TRUE if the request is not valid. if (FALSE) // If (Request is invalid) { // Invalid parameter in the Read request I.Information() = 0; return I.PnpComplete(this, STATUS_INVALID_PARAMETER); } // Always ok to read 0 elements. if (I.ReadSize() == 0) { I.Information() = 0; return I.PnpComplete(this, STATUS_SUCCESS); } // Declare a memory object KMemory Mem(I.Mdl()); ULONG dwTotalSize = I.ReadSize(CURRENT); ULONG dwMaxSize = m_Endpoint2IN.MaximumTransferSize(); // If the total requested read size is greater than the Maximum Transfer // Size for the Pipe, request to read only the Maximum Transfer Size since // the bus driver will fail an URB with a TransferBufferLength of greater // than the Maximum Transfer Size. if (dwTotalSize > dwMaxSize) { ASSERT(dwMaxSize); dwTotalSize = dwMaxSize; } // Allocate a new context structure for Irp completion USB_COMPLETION_INFO* pCompInfo = new (NonPagedPool) USB_COMPLETION_INFO; if (pCompInfo == NULL) { I.Information() = 0; return I.PnpComplete(this, STATUS_INSUFFICIENT_RESOURCES); } // TODO: Select the correct pipe to read from // Create an URB to do actual Bulk read from the pipe PURB pUrb = m_Endpoint2IN.BuildBulkTransfer( Mem, // Where is data coming from? dwTotalSize, // How much data to read? TRUE, // direction (TRUE = IN) NULL, // Link to next URB TRUE // Allow a short transfer ); if (pUrb == NULL) { delete pCompInfo; I.Information() = 0; return I.PnpComplete(this, STATUS_INSUFFICIENT_RESOURCES); } // Initialize context structure pCompInfo->m_pClass = this; pCompInfo->m_pUrb = pUrb; // Submit the URB to our USB device NTSTATUS status; status = m_Endpoint2IN.SubmitUrb(I, pUrb, LinkTo(ReadComplete), pCompInfo, 0); return status; } //////////////////////////////////////////////////////////////////////// // ZboarduDevice::ReadComplete // // Routine Description: // Completion Handler for IRP_MJ_READ // // Parameters: // I - IRP just completed by USB // pContext - Context structure containing pointer to Urb // // Parameters: // NTSTATUS - STATUS_SUCCESS // // Comments: // This routine is called when USBD completes the read request // NTSTATUS ZboarduDevice::ReadComplete(KIrp I, USB_COMPLETION_INFO* pContext) { // Normal completion routine code to propagate pending flag if (I->PendingReturned) { I.MarkPending(); } NTSTATUS status = I.Status(); PURB pUrb = pContext->m_pUrb; ULONG nBytesRead = 0; if ( NT_SUCCESS(status) ) { nBytesRead = pUrb->UrbBulkOrInterruptTransfer.TransferBufferLength; if (nBytesRead > 0) t << \"Read() got \" << nBytesRead<< \" bytes from USB\\n\"; } // Deallocate Urb and context structure delete pUrb; delete pContext; // set returned count I.Information() = nBytesRead; // Plug and Play accounting DecrementOutstandingRequestCount(); // allow IRP completion processing return STATUS_SUCCESS; } |
|
沙发#
发布于:2002-07-27 17:24
你用的是ZBoard板吗?如果是的话,你可以换成DS201编译就好了。
偶问过Ray Yang斑竹,他也遇到过这个问题! |
|
板凳#
发布于:2002-07-29 11:39
谢谢!在DS2.01中确实是可以的,但ds2.5是高版本,在DS2.5中有没有解救的办法。再次谢谢!
|
|
地下室#
发布于:2002-07-29 14:38
谢谢!我还有一事请教:KIrp I,NTSTATUS status 的内容怎样才能在WATCH窗口中看到,我用WATCH I 无法加入,始终是invalid expression.再次谢谢!
|
|