Already done for you http://www.melabs.com/resources/samp...p/serbufAx.bas

Just change the buffer size & tweak to your specs.