简体   繁体   中英

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 reference: 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.

如果仅希望数据最大为1024,则建议保留缓冲区大小。如果希望读取/写入超过4096的数据,则需要相应地调整缓冲区。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM