C#UWP DataReader异常HRESULT:0x8000000B

时间:2018-11-08 14:54:37

标签: c# uwp

我在使用C#UWP DataReader时遇到问题:如果从远程设备执行操作,该软件会引发异常: HRESULT:0x8000000B ....

我的远程设备发送了一个简单的字符串ASCII。

你能帮我吗?

  

代码

UInt32 vid = xxxxxx;
UInt32 pid = xxxxxx;

string aqs = SerialDevice.GetDeviceSelectorFromUsbVidPid((ushort)vid, (ushort)pid);

var myDevices = await DeviceInformation.FindAllAsync(aqs, null);

if (myDevices.Count == 0)
{
  ShowMessage("Device not found!");
  return;
}
else
{
  ShowMessage($"Id: {myDevices[0].Id.Substring(0, 20)}");
  await Task.Delay(500);
}

SerialDevice device = await SerialDevice.FromIdAsync(myDevices[0].Id);

if(device is null)
{
  ShowMessage("Ops...");
  return;
}

ShowMessage($"Port: {device.PortName}\nBaud rate: {device.BaudRate}\nStop bit count: {device.StopBits}\nData bits: {device.DataBits}");
await Task.Delay(500);
using (var dataReader = new DataReader(device.InputStream))
{
  ShowMessage("...");
  await Task.Delay(500);
  ShowMessage("Wait input from device...");

  try
  {
    await dataReader.LoadAsync(1024);

    var receivedString = string.Empty;

    while (dataReader.UnconsumedBufferLength > 0)
    {
      uint byteRead = dataReader.ReadUInt32();
      receivedString += $"{dataReader.ReadString(byteRead)}\n";
      ShowMessage($"Lettura: {receivedString}");
    }

    ShowMessage($"Message: {receivedString}");
  }
  catch(Exception exception)
  {
     ShowMessage($"Error: {exception.Message}\n{exception.StackTrace}");
  }
}

截屏异常 HRESULT:0x8000000B

0 个答案:

没有答案