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
User contributions licensed under CC BY-SA 3.0