I have Arduino connected to serial port. Arduino has the following simple code to send bytes:
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.write((char)100);
}
Code to receive bytes (in separate thread):
int buffersize = 100000;
byte[] buffer = new byte[buffersize];
SerialPort port = new SerialPort("COM3", 9600);
port.ReadBufferSize = buffersize;
port.Open();
int bytesread = 0;
do
{
bytesread = port.BytesToRead;
}
while(bytesread < buffersize && bytesread != buffersize);
port.Read(buffer, 0, buffersize);
I read that BytesToRead can return more than ReadBufferSize because it includes one more buffer. But instead I can receive only nearly 12000 and after that ReadBufferSize doesn't change. The same problem occurs with all baud rates.
So how to read all 100000 bytes in buffer at once? Maybe there are some driver settings etc? Please help.