阅读:1486回复:4
请问D12_ReadWriteRegister??
我看不大明白D12_ReadWriteRegister()这个程序,为什么它还分read、write,他们的目的不都是传递iosize和offset信息吗,实际方向不是都是host->pc吗?为什么它还分in和out呢?请指教!
|
|
沙发#
发布于:2002-10-29 11:36
看名字,应该是读写D12的register。这是MCU和D12之间的事情,和pc没有关系。
|
|
|
板凳#
发布于:2002-10-30 14:16
请斑竹再指点一下,我现在对读寄存器处理时,按照philips的源程序对DeviceIoControl中READ_REGISTER和WRITE_REGISTER写的驱动和应用程序传到固件程序后,iorequest里的所有值都是0,我已经在这里徘徊很久了,本想绕过iorequest这部分,不过好像读必须要才行,请教一下这是怎么回事?
|
|
地板#
发布于:2002-10-30 23:28
没有看过你说的这个程序,不明白!
|
|
|
地下室#
发布于:2002-11-02 23:19
不好意思,我的机子这2天坏了。
我用的是在驱动中定义IOCTL_READ_REGISTERS 和IOCTL_WRITE_REGISTERS,实现的函数是 NTSTATUS D12_ReadWriteRegister( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN BOOLEAN bWrite ) { USBD_INTERFACE_INFORMATION * pInterfaceInfo; PIO_STACK_LOCATION irpStack; PDEVICE_EXTENSION deviceExtension; NTSTATUS ntStatus; PVOID ioBuffer; ULONG length; ULONG inputBufferLength; ULONG outputBufferLength; ULONG siz; PURB urb; USHORT wValue, wIndex; PIO_BLOCK ioBlock; irpStack = IoGetCurrentIrpStackLocation (Irp); ASSERT (irpStack != NULL); deviceExtension = DeviceObject->DeviceExtension; ASSERT (deviceExtension != NULL); ioBuffer= Irp->AssociatedIrp.SystemBuffer; ioBlock = (PIO_BLOCK) ioBuffer; inputBufferLength = irpStack->Parameters.DeviceIoControl.InputBufferLength; outputBufferLength= irpStack->Parameters.DeviceIoControl.OutputBufferLength; siz = sizeof(struct_URB_CONTROL_VENDOR_OR_CLASS_REQUEST); // allocate urb urb = ExAllocatePool(NonPagedPool, siz); length = ioBlock->uLength; wValue = ioBlock->uOffset; wIndex = ioBlock->uIndex; BULKUSB_KdPrint ((\"D12TEST.SYS: ReadWriteRegister: ioBuffer = %p, wIndex = %x, wLength = %lx, wValue = %x.\\n\", ioBlock->pbyData, wIndex, length, wValue)); if (bWrite) { UsbBuildVendorRequest(urb, //ptr to urb URB_FUNCTION_VENDOR_DEVICE, (USHORT) siz, //siz of urb 0, 0x0,//reservedbits=bmRequestType 0x02,//request = USBSCAN IOCTL_WRITE_REGISTER wValue, wIndex, ioBlock->pbyData, NULL, length, NULL); } else { UsbBuildVendorRequest(urb, URB_FUNCTION_VENDOR_DEVICE, (USHORT) siz, USBD_TRANSFER_DIRECTION_IN, 0x0, 0x02, IOCTL_READ_REGISTER, wValue, wIndex, ioBuffer, NULL, length, NULL); }/* else */ ntStatus = BulkUsb_CallUSBD(DeviceObject, urb); if (NT_SUCCESS(ntStatus) && bWrite) { Irp->IoStatus.Information =length; //sizeof (ULONG); }else if (NT_SUCCESS(ntStatus)) { BULKUSB_KdPrint ((\"D12TEST.SYS: Sucessfully Transferred %d Bytes\\n\", urb->UrbControlVendorClassRequest.TransferBufferLength)); Irp->IoStatus.Information = (urb->UrbControlVendorClassRequest.TransferBufferLength); // + sizeof(UCHAR)); } Irp->IoStatus.Status = ntStatus; // free allocated urb ExFreePool(urb); BULKUSB_KdPrint((\"D12TEST.SYS: exit D12_ReadWriteRegister\\n\")); return (ntStatus); } 我的目的是将读和写操作的数目通过一个BuildVendorRequest传递给 固件,我觉得philips的这个程序能传递就直接搬用了,它在应用程序里面是 ioRequest.uAddressL = 0; ioRequest.bAddressH = 0; ioRequest.uSize= threadParam->uiLength; ioRequest.bCommand = 0x81; //start read ioBlock.uOffset= 0; ioBlock.uLength= sizeof(IO_REQUEST); ioBlock.pbyData= (PUCHAR)&ioRequest; ioBlock.uIndex= SETUP_TRANS_REQUEST; bResult = DeviceIoControl(hDevice, IOCTL_WRITE_REGISTERS, (PVOID)&ioBlock, sizeof(IO_BLOCK), NULL, 0, &nBytes, NULL); 固件里面是: memcpy((unsigned char *)&ioRequest + ControlData.DeviceRequest.wValue, ControlData.dataBuffer, ControlData.DeviceRequest.wLength); ioSize = ioRequest.uSize; ioCount = 0; 我监测固件里得到的ioRequest 的值全是0,我想知道为什么放在我的程序里面传递不了正确的值呢? |
|