Saving binary data at the serial port in C#

I have an Arduino code where there is a continuous stream of 16-bit unsigned integers (uint16_t), transmitted LSB first (i.e. little endian).

How can I save this data to a text file in C#?

Why not get the Arduino to send the data as text using Serial.print() ?

...R

Robin2 That doesnt help in my case. That slows down the communication. I just need to read the upcoming uint16 binary data and save it in C#. I have been struggling for this for day. yet no single forum I could find.

I know nothing about C#.

And you have not posted your Arduino program so I can't see exactly what the Arduino is sending.

Can you receive the data in C# as a series of byte values and are you getting the correct values?

For example the value 62000 should be the two bytes 48 and 242 if my maths is correct. You can easily convert those to an integer by multiplying the second number by 256 and adding the first.

I suspect there are cleverer ways to do it with C#. IIRC Python has pack and unpack functions

...R

Whether the data is text or binary does not matter. It is a stream of bytes. What does your Arduino code look like? What does your C# code look like?

How do you expect help with either one without sharing the code?