百分求救:wdm USB驱动,两个device总是会互相影响

ObjLinking 2008-04-02 02:33:02
我的电脑上连了两个USB serial class的device,现在一个拔线之后,另一个的write urb传输也会fail掉,请问各位高手是什么原因?
我看到在OnWriteInterrupt里面两个device object都返回fail,但是我只拔出了一个USB device啊。

NTSTATUS
StartWriteUrb(
PDEVICE_EXTENSION Extension
)
{

// If the interrupt polling IRP is currently running, don't try to start
// it again.
USBD_PIPE_HANDLE PipeHandle;
BOOLEAN startirp;
KIRQL oldirql;
PIRP Irp;
PURB urb;
PIO_STACK_LOCATION stack;

TRACE("Enter StartWriteUrb() size=%d pipehandle=%X\n",Extension->WriteSize,Extension->UsbInterface->Pipes[Extension->DataOutPipe].PipeHandle);

// KeAcquireSpinLock(&Extension->polllock, &oldirql);
if (Extension->writepending)
startirp = FALSE;
else
startirp = TRUE, Extension->writepending = TRUE;
// KeReleaseSpinLock(&Extension->polllock, oldirql);

if (!startirp)
return STATUS_DEVICE_BUSY; // already pending

Irp = Extension->WritingIrp;
urb = Extension->WritingUrb;
PipeHandle = Extension->UsbInterface->Pipes[Extension->DataOutPipe].PipeHandle;

ASSERT(Irp && urb);

// Acquire the remove lock so we can't remove the device while the IRP
// is still active.

// Initialize the URB we use for reading the interrupt pipe

UsbBuildInterruptOrBulkTransferRequest(
urb,
sizeof (struct _URB_BULK_OR_INTERRUPT_TRANSFER),
PipeHandle,
Extension->WriteCurrentChar,
NULL,
Extension->WriteSize,
USBD_TRANSFER_DIRECTION_OUT,
NULL);

// Install "OnInterrupt" as the completion routine for the polling IRP.

IoSetCompletionRoutine(
Irp,
(PIO_COMPLETION_ROUTINE) OnWriteInterrupt,
Extension,
TRUE,
TRUE,
TRUE);

// Initialize the IRP for an internal control request

stack = IoGetNextIrpStackLocation(Irp);
stack->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL;
stack->Parameters.DeviceIoControl.IoControlCode = IOCTL_INTERNAL_USB_SUBMIT_URB;
stack->Parameters.Others.Argument1 = urb;

// This IRP might have been cancelled the last time it was used, in which case
// the cancel flag will still be on. Clear it to prevent USBD from thinking that it's
// been cancelled again! A better way to do this would be to call IoReuseIrp,
// but that function is not declared in WDM.H.

Irp->Cancel = FALSE;

TRACE("Exit StartWriteUrb()\n");

return IoCallDriver(Extension->TopOfStackDeviceObject, Irp);
}
...全文
168 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
tdwang 2009-09-27
  • 打赏
  • 举报
回复
我遇到了类似的问题,在一个应用程序里同时烧写两个(或多个)相同的usb设备,当其中一个意外拔出时,会导致别的设备写失败,如果拔出时别的设备的读操作正在进行则没有影响。我用的不是hub,而是pc机上的两个前置usb插口
麻烦你能详细说一下失败的具体原因并且如何避免吗?谢谢了!
ObjLinking 2008-04-10
  • 打赏
  • 举报
回复
解决了,连在hub上windows会发假的错误消息,只能特殊处理规避了。
用户 昵称 2008-04-05
  • 打赏
  • 举报
回复
应该考虑hub,虽然俺还不怎么明白usb协议,但是我们公司的产品都要经过几层级联hub进行测试.
ObjLinking 2008-04-04
  • 打赏
  • 举报
回复
谢谢,我发现是因为用了hub,请问ddk编程中需要为hub添加相应的code吗?我不用hub的时候都没问题,hub本身没问题,其他驱动的device运行都没问题
oushengfen 2008-04-03
  • 打赏
  • 举报
回复
呵呵,驱动inf与固件中的PID、VID等要统一,两个硬件,要使用不同的即可,还有驱动的GUID或硬描述符,当然也不能一致,否则肯定会有问题的。
ObjLinking 2008-04-02
  • 打赏
  • 举报
回复
另外pipehandle我查下来也没有共用,两个device用的是不同的pipehandle

21,600

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 驱动开发/核心开发
社区管理员
  • 驱动开发/核心开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧