阅读:1152回复:2
怎样发送irp给获得的串口指针??(高分求助)
我的问题是这样的:
在我的dispatch pnp 例程中,处理irp_mn_start_device时,需要获得串口指针,然后打开串口,然后配置串口,监听串口。 现在获得串口指针已经成功,但是打开串口时总是会导致page fault或者自动重启。 我猜测是构建的irp不对,或者发送的方式不对, 恳请高手斧正!! RtlInitUnicodeString( &devx->SerialDeviceName,L\"\\\\Device\\\\Serial0\" ); //Get pointer to serial port status = IoGetDeviceObjectPointer( &devx->SerialDeviceName, FILE_ALL_ACCESS, &pFile, &pSerialDO); //get pSerialDO==the address of PDO 然后帖出我的打开串口的例程,主要问题是irp如何创建,还有如何发送给获得的指针pSerialDO |
|
|
沙发#
发布于:2004-04-13 19:21
NTSTATUS AGSCallSerialOpen( IN PDEVICE_OBJECT DeviceObject )
{ NTSTATUS status = STATUS_SUCCESS; PDEVICE_EXTENSION devx = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension; PSMARTCARD_EXTENSION SmartcardExtension = &devx->SmartcardExtension; PREADER_EXTENSION readerx = SmartcardExtension->ReaderExtension; KEVENT Event; PIO_STACK_LOCATION irpstack; PIRP OpenIrp; OpenIrp = IoAllocateIrp((DeviceObject->StackSize ),FALSE); //这个地方可能有错 irpstack = IoGetNextIrpStackLocation( OpenIrp ); irpstack->FileObject = pFileObj;//ioGetDeviceObjectPointer中的那个FileObject irpstack->MajorFunction = IRP_MJ_CREATE; irpstack->DeviceObject = readerx->SerialDeviceObject; irpstack->Parameters.Create.Options = 0; irpstack->Parameters.Create.ShareAccess = 0; irpstack->Parameters.Create.FileAttributes = 0; irpstack->Parameters.Create.EaLength = 0; // // initialize an event for process synchronization. The event is passed // to our completion routine and will be set when the serial driver is done // KeInitializeEvent( &Event, NotificationEvent, FALSE ); // Our IoCompletionRoutine sets only our event //S:registers an IoCompletion routine to be called when the next-lower-level driver //has completed the requested operation for the given IRP. IoSetCompletionRoutine ( OpenIrp, AGSIoCompletion, DeviceObject, TRUE, TRUE, TRUE ); // Call the serial driver //S:sends an IRP to the next-lower-level driver(SERIAL DRIVER) after //the caller has set up the I/O stack location in the IRP for that driver status = IoCallDriver(readerx->SerialDeviceObject, OpenIrp); // Wait until the serial driver has processed the Irp if (status == STATUS_PENDING) { status = KeWaitForSingleObject( &Event, Executive, KernelMode, FALSE, NULL ); ASSERT (STATUS_SUCCESS == status); status = OpenIrp->IoStatus.Status; } return status; } |
|
|
板凳#
发布于:2004-04-13 19:26
我把获得的串口指针保存在了readerx->SerialDeviceObject。
现在是一头雾水,因为我的status = IoCreateDevice( pDriverObject, sizeof(DEVICE_EXTENSION), &(UNICODE_STRING)DevName, FILE_DEVICE_SMARTCARD, 0, FALSE, &DeviceObject ); DeviceObject和获得的指针没有IoAttachDeviceToDeviceStack,这种情况下必须自己构建一个irp来发送给串口吧, 但是这种情况下如何处理? 尤其是irp的构建,irpstack的初始化,还有对于用 iogetdeviceobjectpointer获得的deviceobject的使用,着实没有什么头绪。 希望大家提出宝贵的意见,谢谢!! :) 我会不吝惜分数的 |
|
|