我正在研究UWP应用程序(通用Windows),我遇到了这个问题,我希望你的才能会对我有所帮助。问题是我插入耳机HidDevice从该耳机读取固件版本。
这是我的代码:
public async void ReadFirmwareVersion()
{
if (DeviceManagerEventHandler.Current.HidDevice != null)
{
HidOutputReport outReport = DeviceManagerEventHandler.Current.HidDevice.CreateOutputReport();
byte[] buffer = queryVersion();
DataWriter dataWriter = new DataWriter();
dataWriter.WriteBytes(buffer);
outReport.Data = dataWriter.DetachBuffer();
await DeviceManagerEventHandler.Current.HidDevice.SendOutputReportAsync(outReport);
HidInputReport inReport = await DeviceManagerEventHandler.Current.HidDevice.GetInputReportAsync();
if (inReport != null)
{
UInt16 id = inReport.Id;
var bytes = new byte[64];
DataReader dataReader = DataReader.FromBuffer(inReport.Data);
dataReader.ReadBytes(bytes);
}
else
{
rootPage.NotifyUser("Invalid input report received", NotifyType.ErrorMessage);
}
}
}
public static Byte[] queryVersion()
{
Byte[] cmd = new Byte[64];
cmd[0] = 0x0B;
cmd[1] = 0x11;
return cmd;
}
我收到了错误 outReport.Data = dataWriter.DetachBuffer(); 他们说 Value does not fall within the expected range HidInputReport inReport = await DeviceManagerEventHandler.Current.HidDevice.GetInputReportAsync(); 是另外一个错误 A device attached to the system is not functioning
我试图获取耳机固件版本但由于这些错误而无法解决问题。请帮忙,我差不多花了2天。我做错了吗?