C#:SerialPort: read and write buffer size
I am writing a program to send and receive data via a serial port with C#.
Although I have read this refere开发者_Go百科nce: http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.readbuffersize.aspx, I am not quite clear if I change the values of the buffer for reading and writing:
serialPort.ReadBufferSize = 1; // or 1024 ?
serialPort.WriteBufferSize = 1;// or 1024 ?
The values (1 or 1024) should be better to be smaller or bigger?
Thanks in advance.
The link you provided states:
SerialPort.ReadBufferSize Property
The default value is 4096.
The ReadBufferSize property ignores any value smaller than 4096.
It also states that setting an odd integer size throws an exception.
I would suggest leaving the buffer sizes if you are only expecting your data to be a max of 1024. If you were expecting to read/write data in excess of 4096, then you would need to adjust the buffer accordingly.
精彩评论