C# UWP DataReader exception HRESULT: 0x8000000B

0

I've a problem with C# UWP DataReader: in event action from my remote device, the software raise an exception: HRESULT: 0x8000000B....

My remote device sent a simple string ASCII.

Can you help me?

Code

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}");
  }
}

Screenshot exception HRESULT:0x8000000B

c#
uwp
asked on Stack Overflow Nov 8, 2018 by Nicolò • edited Nov 8, 2018 by David Browne - Microsoft

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0