fubow
驱动牛犊
驱动牛犊
  • 注册日期2007-08-24
  • 最后登录2007-08-27
  • 粉丝0
  • 关注0
  • 积分10分
  • 威望2点
  • 贡献值0点
  • 好评度1点
  • 原创分0分
  • 专家分0分
阅读:780回复:0

请教:在用DriverStudio3.1开发的USB驱动,VC++访问正常,C#访问出错

楼主#
更多 发布于:2007-08-24 15:37

在用DriverStudio3.1开发的USB驱动程序,来访问D12设备,读文件的代码如下所示:

问题,在用VC++开发程序进行文件读写时,如果读写超时(比如固件程序没有响应),则能在100ms后返回

但是在用C#开发的程序来进行文件读写时,如果读写超时,程序就回死在读写的函数处

现在不知道是C#调用驱动的机制有不同,还是我的驱动程序有问题。


NTSTATUS TzUSBDevice::Read(KIrp I)
{
    ...........

    // Create an URB to do actual Bulk read from the pipe
    PURB pUrb = m_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)
    {
        I.Information() = 0;
        return I.PnpComplete(this, STATUS_INSUFFICIENT_RESOURCES);
    }

    ULONG nBytesRead = 0;

    // Submit the URB to our USB device, synchronously - say less is OK
    pUrb->UrbBulkOrInterruptTransfer.TransferFlags =
            (USBD_TRANSFER_DIRECTION_IN | USBD_SHORT_TRANSFER_OK);
    
    // Submit the URB to our USB device
    NTSTATUS status;
    status = m_m_Endpoint2IN.SubmitUrb( pUrb, NULL, NULL, 100 );

    if ( NT_SUCCESS(status) )
    {
        nBytesRead = pUrb->UrbBulkOrInterruptTransfer.TransferBufferLength;
    }

    delete pUrb;

    I.Information() = nBytesRead;

    return I.PnpComplete(this, status, IO_NO_INCREMENT);
}


游客

返回顶部