// 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读回采样值。

  • UC3846控制芯片工作原理控制图 逆变焊机原理与用途
  • 数字万用表电阻档测试二极管正反向没有阻值(使用万用表测量二极管的正向电阻,为什么各档)
  • 学单片机需要学数电模电吗(学单片机要先学数电模电吗)
  • 电工怎么选择适合自己用的万用表(电工初学者买什么样的万用表好)
  • 单片机需要同时运行多个任务怎么办(单片机怎么同时执行多个任务)
  • 电机保护的方案取决于负载的机械特性
  • 绝缘电阻表正负搭接不复零位是怎么回事
  • 短路怎么用万用表查