C#UWP HidDevice.FromIdAsync总是返回null

时间:2018-03-06 09:33:41

标签: c# uwp visual-studio-2017 device human-interface

我正在使用Visual Studio 2017(版本15.5.7),我将创建一个尝试与Hid设备连接的UWP项目。这是我的代码

DECLARE 
        callDuration VARCHAR2(10);
    BEGIN
        SELECT
            tbl.event_data.currentagentsnapshot.contacts
        FROM
            tbl_agent_event_json tbl;
    BEGIN
       callDuration := CURRENT_TIMESTAMP - tbl.event_data.currentagentsnapshot.contacts[0].StateStartTimestamp;
    END;

尽管deviceInformation显示正确的imfo。关于我的设备,但是 private async void EnumerateHidDevices() { ushort VID = 0x0416; ushort PID = 0x412C; ushort usagePage = 0x000c; ushort usageId = 0x0001; string selector = HidDevice.GetDeviceSelector(usagePage, usageId,VID,PID); var deviceInformation = await DeviceInformation.FindAllAsync(selector); if(deviceInformation.Count!=0) { try { if (deviceInformation != null && deviceInformation.Count > 0) { HidDevice hidDevice = await HidDevice.FromIdAsync(deviceInformation[0].Id,FileAccessMode.ReadWrite); } else { TextBox_1.Text += "" + Environment.NewLine + "Device Information=null"; } } catch(Exception ex) { TextBox_1.Text +=""+Environment.NewLine+ "hidDevice Connect Fail!"+Environment.NewLine+ex; } } } 返回null。

我尝试使用FileAccessMode.Read和ReadWrite,两者都获得异常说明 “System.NullReferenceException:对象引用未设置为对象的实例。”

我确信该设备可以连接并发送其他应用程序的报告,我也审查了UWP Hid的文档。 如何正确连接我的hidDevice?

0 个答案:

没有答案