|
做USB驱动无法读回数据,请各位高手帮忙看下这段代码是不是有错....谢过 !
[复制链接]
- void THVMSDevice::SerialRead(KIrp I)
- {
- T.Trace(TraceInfo, __FUNCTION__"++. IRP %p\n", I);
- T.Trace(TraceInfo, __FUNCTION__"gotoRead -----successful!\n");
- NTSTATUS status = STATUS_SUCCESS;
- KMemory Mem(I.Mdl()); // Declare a memory object
- // Get a pointer to the caller's buffer. Note that this
- // routine is safe on all platforms.
- PUCHAR pBuffer = (PUCHAR)Mem.MapToSystemSpace();
- ULONG readSize = I.ReadSize();
- ULONG bytesRead = 0;
- BOOLEAN bshortOK = TRUE;
- T.Trace(TraceInfo, __FUNCTION__"++. READSIZE: %l \n",readSize);
- // TODO: At this point, perform any processing for IRP_MJ_READ
- // To satisfy the read now, transfer data from the driver
- // to the caller's buffer at "pBuffer". Then, indicate
- // how much data was transferred:
- //I.Information() = bytesRead;//临时注释掉
- I.Status() = status;
-
- // NextIrp completes this IRP and starts processing
- // for the next IRP in the driver managed queue.
- if ((readSize>PAGE_SIZE)||(readSize<64))
- {
- T.Trace(TraceInfo, __FUNCTION__"@@@@@@@Readsizeout!\n");
- I.Status() = STATUS_INVALID_PARAMETER;
- ReadQueue.PnpNextIrp(I);
- }
- else
- {
- // TODO: copy data
- // To satisfy the ioctl now, transfer data using the
- // caller's buffers at "inputBuffer" and/or "outputBuffer".
- // Then, indicate how much data was transferred:
- bshortOK = readSize
-
- PURB pUrb =Pipe0.BuildBulkTransfer(Mem,readSize,TRUE,NULL,bshortOK,NULL);
- if(NULL == pUrb)
- {
- T.Trace(TraceInfo, __FUNCTION__"URB IS NULL!!!!!!!!\n");
- I.Status() = STATUS_INSUFFICIENT_RESOURCES;
- ReadQueue.PnpNextIrp(I);
- }
- else
- {
- status = Pipe0.SubmitUrb(pUrb,LinkTo(OnTransferComplete),this,100);
- if ( !NT_SUCCESS(status) )
- {
- T.Trace(TraceInfo, __FUNCTION__"SerialRead -----failed!\n");
- I.Status() = status;
- }
- else
- {
- T.Trace(TraceInfo, __FUNCTION__"SerialRead -----successful!\n");
- }
- ReadQueue.PnpNextIrp(I);
-
- }
- }
- T.Trace(TraceInfo, __FUNCTION__"--. IRP %p, STATUS %x\n", I, status);
- }
复制代码
|
|