// IrpStack-》ParAMEters.Read.xxx has read parameters
// User buffer at: AssociatedIrp.SystemBuffer (buffered I/O)
// MdlAddrESS (direct I/O)
//
// Return Value:
// This function returns STATUS_XXX
NTSTATUS UsbgatherRead( IN PDEVICE_OBJECT fdo,
IN PIRP Irp)
{
PUSBgather_DEVICE_EXTENSION dx = (PUSBgather_DEVICE_EXTENSION)fdo-》DeviceExtension;
if( dx-》IODisabled)
return CompleteIrp( Irp, STATUS_DEVICE_NOT_CONNECTED, 0);
if (!LockDevice(dx))
return CompleteIrp( Irp, STATUS_DELETE_PENDING, 0);
PIO_STACK_LOCATION IrpStack = IoGetCurrentIrpStackLocation(Irp);
NTSTATUS status = STATUS_SUCCESS;
ULONG BytesTxd = 0;
// 得到参数
LONGLONG FilePointer = IrpStack-》Parameters.Read.ByteOffset.QuadPart;
ULONG ReadLen = IrpStack-》Parameters.Read.Length;
// 检查文件指针
if( FilePointer《0)
status = STATUS_INVALID_PARAMETER;
else
{
status = UsbDoInterruptTransfer( dx, Irp-》AssociatedIrp.SystemBuffer, ReadLen);
BytesTxd = ReadLen;
}
// 完成 IRP
CompleteIrp(Irp,status,BytesTxd);
UnlockDevice(dx);
return status;
}
/////////////////////////////////////////////////////////////////////////////
// UsbgatherWrite:
//
// Description:
// Handle IRP_MJ_WRITE requests
//
// Arguments:
// Pointer to our FDO
// Pointer to the IRP
// IrpStack-》Parameters.Write.xxx has write parameters
// User buffer at: AssociatedIrp.SystemBuffer (buffered I/O)
// MdlAddress (direct I/O)
//
// Return Value:
// This function returns STATUS_XXX
NTSTATUS UsbgatherWrite( IN PDEVICE_OBJECT fdo,
IN PIRP Irp)
{
PUSBgather_DEVICE_EXTENSION dx = (PUSBgather_DEVICE_EXTENSION)fdo-》DeviceExtension;
if( dx-》IODisabled)
return CompleteIrp( Irp, STATUS_DEVICE_NOT_CONNECTED, 0);
if (!LockDevice(dx))
return CompleteIrp( Irp, STATUS_DELETE_PENDING, 0);
PIO_STACK_LOCATION IrpStack = IoGetCurrentIrpStackLocation(Irp);
NTSTATUS status = STATUS_SUCCESS;
ULONG BytesTxd = 0;
// 得到参数
LONGLONG FilePointer = IrpStack-》Parameters.Write.ByteOffset.QuadPart;
ULONG WriteLen = IrpStack-》Parameters.Write.Length;
if( FilePointer《0 || WriteLen《1)
status = STATUS_INVALID_PARAMETER;
else
{
// 仅写一个字节
BytesTxd = 1;
PUCHAR pData = (PUCHAR)Irp-》AssociatedIrp.SystemBuffer;
UsbSendOutputReport( dx, *pData);
}
// 完成 IRP
CompleteIrp(Irp,status,BytesTxd);
UnlockDevice(dx);
return status;
}
应用程序采用标准的文件操作方法。使用CreateFile API打开文件。使用WriteFile API发出开始命令,启动ADC,使用ReadFile读回采样值。