kindle
驱动牛犊
驱动牛犊
  • 注册日期2007-09-18
  • 最后登录2009-10-30
  • 粉丝0
  • 关注0
  • 积分1分
  • 威望15点
  • 贡献值0点
  • 好评度4点
  • 原创分0分
  • 专家分0分
阅读:1870回复:1

USB Bulk 读的问题

楼主#
更多 发布于:2008-05-22 17:29
当读的长度小于设备发送的长度的时候就会出错,测试程序读4个字节,但是设备发送了100个字节
  URB Bulk or Interrupt Transfer issued
Device Object    USBPDO-8
Driver Object    usbhub

URB Function    URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER

Endpoint 81h    1 In, Bulk

Transfer Buffer Length    4

  URB Bulk or Interrupt Transfer failed
Device Object    USBPDO-8
Driver Object    usbhub

URB Function    URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER
URB Status    USBD_STATUS_BABBLE_DETECTED
Endpoint 81h    1 In, Bulk

Transfer Buffer Length    0


使用DS3.2产生的模板改的代码如下:

NTSTATUS V990USBDevice::Read(KIrp I)
{
    T << "Entering DRVDevice::Read, " << I << EOFL;
// 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 = Pipe1.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 = Pipe1.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 = Pipe1.SubmitUrb(I, pUrb, LinkTo(ReadComplete), pCompInfo, V990_DEFAULT_TIMEOUT);
    return status;
}


先谢谢了

最新喜欢:

eda_gbeda_gb
GoodOnline
驱动小牛
驱动小牛
  • 注册日期2007-04-11
  • 最后登录2009-02-28
  • 粉丝0
  • 关注0
  • 积分4分
  • 威望204点
  • 贡献值0点
  • 好评度191点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2008-05-23 14:24
建议搂住看下 ddk中usb里的例子代码, 里面的配置部分可是很有价值的!
游客

返回顶部