c# - How can I use readbyte function faster -


i'm using serialport in c# , code this:

filestream myfile = new filestream(strfiledestination, filemode.append); binarywriter bwfile = new binarywriter(myfile); bwfile.write(serialport1.readexisting()); bwfile.close(); myfile.close(); 

when use

bwfile.write(serialport1.readbyte()); 

instead of

bwfile.write(serialport1.readexisting()); 

, writing speed in file decreases 130 kb/s 28 kb/s , when use

bwfile.write((byte)serialport1.readbyte()); 

, writing speed decreases 7 kb/s. want know how can write in file third command , have speed 130 kb/s.

have considered using stream write data? don't think using features binarywriter offers on stream.write.

simply call copyto() method

stream destination = new filestream(...) myfile.copyto(destination); 

which under hood calling following code:

byte[] buffer = new byte[buffersize]; int read; while ((read = serialport1.read(buffer, 0, buffer.length)) != 0) {     destination.write(buffer, 0, read); } 

have @ post further information: https://stackoverflow.com/a/411605/283787


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -