阅读:1858回复:9
DriverStudio 做好了驱动,怎么读取到的数据总是0?
原来的驱动用的是别人提供的,是用端口1做输入,端口2输出,都是中断方式,电脑应用程序读取数据没有问题
现在打算改用DriverStudio做了一个驱动,用的是VC 6.0+XP DDK+Driver Studio 3.2,采用同样的设置,驱动安装之后运转正常,可以得到设备的描述符,可是读数据始终是0 再换上原来的驱动就是好的,想请教各位一下是什么原因 |
|
沙发#
发布于:2007-08-13 15:36
引用第0楼sky_sun_wei于2007-08-13 11:47发表的 DriverStudio 做好了驱动,怎么读取到的数据总是0? : 可能是固件的原因,我现在也是读到全0,或全F 很郁闷,不知道怎么办 |
|
板凳#
发布于:2007-08-13 16:06
Bus Hound 看到确实读取到了数据了呀
|
|
地板#
发布于:2007-08-14 11:44
顶一下
换个Driver Studio的驱动就应用软件不成了,从 Bus Hound 看到的驱动接口和原来是一样的呀! |
|
地下室#
发布于:2007-08-14 13:15
我看里面还有好多IRP代码没有加把,我也这个问题,现在还在拼命看书呢
|
|
5楼#
发布于:2007-08-14 16:58
就是用 DriverStdudio 生成的Read代码
NTSTATUS UsbUseDevice::Read(KIrp I) { T.Trace(TraceInfo, __FUNCTION__"++. IRP %p\n", I); NTSTATUS status = STATUS_SUCCESS; // TODO: Validate the parameters of the IRP. Replace "FALSE" // in the following line with error checking code that // evaulates to TRUE if the request is not valid. if (FALSE) { status = STATUS_INVALID_PARAMETER; I.Information() = 0; I.PnpComplete(status); T.Trace(TraceWarning, __FUNCTION__"--. IRP %p, STATUS %x\n", I, status); return status; } // Always ok to read 0 elements if (I.ReadSize() == 0) { I.Information() = 0; I.PnpComplete(this, status); T.Trace(TraceInfo, __FUNCTION__"--. IRP %p, STATUS %x\n", I, status); return status; } 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; // 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.PnpComplete(this, status); T.Trace(TraceInfo, __FUNCTION__"--. IRP %p, STATUS %x\n", I, status); return status; } 的 TODO 后面是否还需要添加代码? |
|
6楼#
发布于:2007-08-15 08:02
你根本没有建urb向下面发,怎么可能读到数据呢?还是先去看看DS的例子再说
|
|
|
7楼#
发布于:2007-08-16 00:02
,多谢大大
|
|
8楼#
发布于:2007-09-24 11:48
引用第6楼rayyang2000于2007-08-15 08:02发表的 : 我是新手,请问在哪里建urb,能写几句简单的代码吗? |
|
9楼#
发布于:2007-09-27 16:47
ULONG dwMaxSize = m_Endpoint1IN.MaximumTransferSize();
if ( dwTotalSize > dwMaxSize ) { ASSERT (dwMaxSize); dwTotalSize = dwMaxSize; // Only allowed to read maxsize, in this case, 16K. } PURB pUrb = m_Endpoint1IN.BuildInterruptTransfer ( Mem, // Data read from dwTotalSize, // Data buffer to receive TRUE, // Transmit less than Size is OK NULL, // Link to next URB NULL, // Allocate a new URB TRUE // direction ( TRUE = IN ) ); if ( pUrb != NULL ) { // Submit the Urb to our USB device. pUrb->UrbBulkOrInterruptTransfer.TransferFlags = ( USBD_TRANSFER_DIRECTION_IN | USBD_SHORT_TRANSFER_OK ); status = m_Endpoint1IN.SubmitUrb (pUrb, NULL, NULL); if ( NT_SUCCESS(status) ) { dwBytesRead = pUrb->UrbBulkOrInterruptTransfer.TransferBufferLength; if (dwBytesRead > 0) { t << "Read() got" << dwTotalSize << " bytes from USB\n"; } } delete pUrb; } |
|