HidDevice.GetInputReportAsync 方法

定义

重载

GetInputReportAsync()

异步检索给定 HID 设备中的默认或第一个输入报告。

GetInputReportAsync(UInt16)

从给定 HID 设备异步检索由 reportId 参数标识的输入报告。

GetInputReportAsync()

异步检索给定 HID 设备中的默认或第一个输入报告。

public:
 virtual IAsyncOperation<HidInputReport ^> ^ GetInputReportAsync() = GetInputReportAsync;
/// [Windows.Foundation.Metadata.Overload("GetInputReportAsync")]
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncOperation<HidInputReport> GetInputReportAsync();
[Windows.Foundation.Metadata.Overload("GetInputReportAsync")]
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncOperation<HidInputReport> GetInputReportAsync();
function getInputReportAsync()
Public Function GetInputReportAsync () As IAsyncOperation(Of HidInputReport)

返回

HidInputReport 对象。

属性

示例

在这里,我们将检索 input 报表 (inputReport) ,并在异步调用完成时触发的 InputReportReceived 事件的处理程序中获取报表的内容。

HidInputReport inputReport = await device.GetInputReportAsync();
.
.
.
private void InputReportReceived(
    HidDevice sender, 
    HidInputReportReceivedEventArgs args)
    {
        HidInputReport inputReport = args.Report;
        IBuffer buffer = inputReport.Data;
        DataReader dr = DataReader.FromBuffer(buffer);
        byte[] bytes = new byte[inputReport.Data.Length];
        dr.ReadBytes(bytes);

        String inputReportContent = 
           System.Text.Encoding.ASCII.GetString(bytes);
    }

注解

此方法完成后,将触发 InputReportReceived 事件。

若要访问输入报表的内容,必须为 InputReportReceived 事件设置侦听器,并在事件处理程序中获取 HidInputReportReceivedEventArgs 对象的 Report 属性。

必须使用 FileAccessMode.ReadFileAccessMode.ReadWrite 打开设备。

适用于

GetInputReportAsync(UInt16)

从给定 HID 设备异步检索由 reportId 参数标识的输入报告。

public:
 virtual IAsyncOperation<HidInputReport ^> ^ GetInputReportAsync(unsigned short reportId) = GetInputReportAsync;
/// [Windows.Foundation.Metadata.Overload("GetInputReportByIdAsync")]
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncOperation<HidInputReport> GetInputReportAsync(uint16_t const& reportId);
[Windows.Foundation.Metadata.Overload("GetInputReportByIdAsync")]
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncOperation<HidInputReport> GetInputReportAsync(ushort reportId);
function getInputReportAsync(reportId)
Public Function GetInputReportAsync (reportId As UShort) As IAsyncOperation(Of HidInputReport)

参数

reportId
UInt16

unsigned short

uint16_t

标识请求的输入报告。

返回

HidInputReport 对象。

属性

示例

在这里,我们将检索 input 报表 (inputReport) ,并在异步调用完成时触发的 InputReportReceived 事件的处理程序中获取报表的内容。

HidInputReport inputReport = await device.GetInputReportAsync();
.
.
.
private void InputReportReceived(
    HidDevice sender, 
    HidInputReportReceivedEventArgs args)
    {
        HidInputReport inputReport = args.Report;
        IBuffer buffer = inputReport.Data;
        DataReader dr = DataReader.FromBuffer(buffer);
        byte[] bytes = new byte[inputReport.Data.Length];
        dr.ReadBytes(bytes);

        String inputReportContent = 
           System.Text.Encoding.ASCII.GetString(bytes);
    }

注解

此方法完成后,将触发 InputReportReceived 事件。

若要访问输入报表的内容,必须为 InputReportReceived 事件设置侦听器,并在事件处理程序中获取 HidInputReportReceivedEventArgs 对象的 Report 属性。

必须使用 FileAccessMode.ReadFileAccessMode.ReadWrite 打开设备。

适用于