I'm using Visual Studio 2017(version 15.5.7) ,I'm going to create a UWP project which try to connect with Hid Device .Here are my codes
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;
}
}
}
Although deviceInformation shown correct imfo. about my device,but
HidDevice.FromIdAsync()
return null.
I'd try to FileAccessMode.Read and ReadWrite , both were get the exception says "System.NullReferenceException: Object reference not set to an instance of an object."
I'm sure that device can connect and send report on other application,and I also had review the document of UWP Hid . How can I correctly connected with my hidDevice??