Best way to receive large amount of data from serial port in C#

0

I am currently working on a project where I have to receive 128 MB of data from the serial port. I have PCB where there is 128MB FLASH and a Microcontroller on it. I connected a FTDI board from microcontroller to my PC. My basic algorithms work like this:

  1. I send Address I want to read (at start 0x00000000) to microcontroller with preambles and stuff:
  2. Microcontroller reads 256 Bytes from FLASH and transmits through Serial channel.
  3. Received data is written to a text file.
  4. Increment memory 256 bytes then send address again.

Basically that's it.

On my PC I wrote simple program in C# that configures and opens the port of serial channel then transmit address when I click the button.

However, I have noticed that some of the data is wrong. For example I got 0x09 0x00 instead of 0x09 0xcf. Some of the data are zeros.

pseudo code is below:

while (Page < End_Of_Memory)
{
    SerialPort.Write(Command_n_PageAddress);
    SerialPort.Read(InputBuffer,0,256);
    Stream.Write(MyTxtFile.txt,0,256);
    Page++;
}

Baudrate of Serial Channel = 2Mbps

Why am I receiving 0x00 sometimes? Also is this the correct way to read from serial port? Should I wait for some time so that data transmission is complete and then read the buffer? What else can I do to make sure the correct data is received when dealing with this much of data(Maybe simple checksum)?

c#
serial-port
asked on Stack Overflow Nov 14, 2020 by NOpE • edited Nov 14, 2020 by marc_s

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0