Click here to Skip to main content
16,018,006 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello.
I'm developing a UWP application that opens a
"SerialDevice" that is a CYPRESS ARM
micrcontroller with "Azure RTOS" and "USBX" library.

The "USBX" library instantiates CDC ACM connection.

The micrcontroller send every second a USB packet with a unknown length from 8 to 512 bytes.

I have to read this packet in my UWP application.

I use this code.

C#
async void my_routine(SerialDevice serialDevice)
{

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

  while(true)
  {
     // wait packet
     await dataReader.LoadAsync(512);

     // Read first byte that is an OPERATION_CODE
     var opCode = dataReader.ReadByte();
  }
}


I don't understand why the code stucks at

C#
await dataReader.LoadAsync(512);


even if I set

C#
InputStreamOptions = InputStreamOptions.Partial


where microsoft ensures

Quote:
The asynchronous read operation completes when one or more bytes is available.


Can someone help me ?

What I have tried:

I try not to use

C#
await dataReader.LoadAsync(512);


I try to use

C#
await dataReader.LoadAsync(1);


and calculate how many bytes from OPERATION_CODE
Posted
Comments
[no name] 4-Feb-21 10:10am    
Seems there a lot more to the story than what you're showing.

https://docs.microsoft.com/en-us/uwp/api/windows.devices.serialcommunication.serialdevice?view=winrt-19041
Mauro Fantina 5-Feb-21 2:13am    
What I'm missing ?
[no name] 5-Feb-21 6:41am    
You've shown a useless code "fragment" ... we're supposed to "assume" you did the proper setup. Some of us don't (assume).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900