0

I work on serial Port to read data. serial port's baud-rate is 921600 bps and i use these code to read data:

    while(true)
    {
      bytesToRead = sensor.BytesToRead;
      if (bytesToRead > 0)
      {
        byte[] input = new byte[bytesToRead];
        sensor.Read(input, 0, bytesToRead);
      }
   }

sending protocols is like this. (five digit numbers in bytes + \n\r )

48 48 49 52 50 10 13 , ....

that means : "00142\n\r"  -> 00142 -> 142 

in each loop I read 4096 bytes of data and i looking for fast way to read all numbers in buffer. i use readLine() function also but it is too slow and some data has been lost.

is there any idea what shroud i do? thanks.

  • Hardware platform? Operating system? Programming language? BTW the *"sending protocols [sic]"* appears to be a line of ASCII text. A HLL program that reads byte-by-byte instead of a line is not going to be *"in highspeed mode'*. – sawdust May 29 '21 at 20:18
  • At a data rate of 921600 bps, it's very unlikely that readLine() is too small. For today's computer, 921600 bps is a very slow speed. How do you know the data has been sent in the first place? – Codo Jun 11 '21 at 12:27

0 Answers0