CanWin
驱动牛犊
驱动牛犊
  • 注册日期2002-07-26
  • 最后登录2002-10-24
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1068回复:0

有关 dwMaxSize = m_Endpoint1OUT.MaximumTransferSize() 返回值为0的问题

楼主#
更多 发布于:2002-08-21 16:26
专家,很高兴你能给我解决问题.
.我用DriverWorks为我的usb to rs232建一个驱动程序.在DirverWirzard中选择了bulk方式,endPoint1IN和endPoint1OUT,缓冲区设置为64和64,采用有缓冲的I/O方式,不设置特定的IOCTL.系统然后自动创建.SYS和测试的程序.我已成功安装了.SYS,但我运行自动创建的测试程序.EXE时带参数 W 32,即写32个字符,设备打开正常,但发现系统出现致命错误0E,蓝屏.我用SOFT-ICE跟踪是发现NTSTATUS UsbRs232Device::Write(KIrp I) 中有一句调用返回值不对:
 ULONG dwTotalSize = I.WriteSize(CURRENT); // 此句返回值为:32 正确
 ULONG dwMaxSize = m_Endpoint1OUT.MaximumTransferSize(); // 此句返回值为:0, 不对,应该是64.
上面最后一句调用返回值为0,即dwMaxSize=0.后来我怀疑我在初始化时没有设置对,看了设备的构造函数发现是对的:
 m_Endpoint1OUT.Initialize(m_Lower, 0x1, 64);
我现在搞不明白为什么dwMaxSize会为0呢?以下是我的Write(KIrp I)函数(我对自动产生的驱动程序还没有改任何一行程序呢,怎么会出错呢),请你给我看一下,好吗?谢谢.
 
NTSTATUS UsbRs232Device::Write(KIrp I)
{
 t << \"Entering UsbRs232Device::Write, \" << 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)
 {
  // Invalid parameter in the Write request
  I.Information() = 0;
  return I.PnpComplete(this, STATUS_INVALID_PARAMETER);
 }
 
 // Always ok to write 0 elements.
 if (I.WriteSize() == 0)
 {
  I.Information() = 0;
  return I.PnpComplete(this, STATUS_SUCCESS);
 }
 ULONG dwTotalSize = I.WriteSize(CURRENT);
 ULONG dwMaxSize = m_Endpoint1OUT.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;
 }
 
 PUCHAR pBuffer = (PUCHAR)I.BufferedWriteSource();
 
 KMemory Mem(pBuffer, dwTotalSize);
 Mem.SetPageArray();
 
 // 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 write to
 
 // Create an URB to do actual Bulk write to the pipe
 PURB pUrb = m_Endpoint1OUT.BuildBulkTransfer(
     Mem,          // Where is data coming from?
     dwTotalSize,  // How much data to read?
     FALSE,        // direction (FALSE = OUT)
     NULL    // Link to next URB
     );        
 
 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_Endpoint1OUT.SubmitUrb(I, pUrb, LinkTo(WriteComplete), pCompInfo, 0); // 执行到此处就蓝屏,呀,MY GOD
 return status;
}



[编辑 -  8/21/02 by  CanWin] :(

[编辑 -  8/21/02 by  CanWin]

最新喜欢:

xzycqxzycq
游客

返回顶部