阅读:1916回复:2
两个Bulk in Endpoint,在Read函数中怎样区分?---DS
NTSTATUS UCANDevice::Read(KIrp I)
{ t << "Entering UCANDevice::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_Endpoint1IN.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_Endpoint1IN.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_Endpoint1IN.SubmitUrb(I, pUrb, LinkTo(ReadComplete), pCompInfo, 0); return status; } //////////////////////////////////////////////////////////////////////// // UCANDevice::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 UCANDevice::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; } // BULK Pipe for USB endpoint 1 IN (address 0x81) KUsbPipe m_Endpoint1IN; // BULK Pipe for USB endpoint 2 OUT (address 0x2) KUsbPipe m_Endpoint2OUT; // BULK Pipe for USB endpoint 3 IN (address 0x83) KUsbPipe m_Endpoint3IN; 用DS2.7生成了代码,可以对Endpoint1以Bulk方式读,Endpoint2以Bulk方式写,Endpoint3也是Bulk方式的IN端口,怎样在NTSTATUS UCANDevice::Read(KIrp I){}函数中 加入读Endpoint3代码,用来区分是对Endpoint1 ,还是Endpoint3的读操作呢? |
|
沙发#
发布于:2009-01-09 17:34
设置活动端点就可以了!或者多增加几个这样的函数就可以了!
|
|
|
板凳#
发布于:2008-07-22 14:13
自己顶一下.
难了好几天的问题,怎么区分呢? |
|