Read unknown length packets from SerialDevice

Mauro Fantina 106 Reputation points
2021-02-05T07:07:44.497+00:00

Hello.

I develop a UWP app that has to read packets with unknown length from USB-SerialPort.

Packet length is from 8 to 512 bytes.

This packets are sent periodically (about at one packet per second) from external ARM device where Azure RTOS and USBX library runs .

The code I used to read this packets is ...

void my_routine(SerialDevice serialDevice)
{

  var dataReader = new DataReader(serialDevice.InputStream)
  {
    InputStreamOptions = InputStreamOptions.Partial
  };

  // asyncronous wait for max packet length, InputStreamOptions is set to Partial Read
  await dataReader.LoadAsync(512);

  // Read first byte of the packet : this is the OPERATING CODE
  var op_code = dataReader.ReadByte();
}

What I see is that the code is stuked at "await dataRead.LoadAsync" till total number of bytes reach 512.

I deduce that "InputStreamOptions.Partial" not work for me.

With WireShark and USBPcap I see that this packets came correcty to my PC but code is always stucked at "await dataRead.LoadAsync".

Can someone help me ?

Universal Windows Platform (UWP)
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.