Serial Comm - buffering

  • Thread starter Thread starter Amjad
  • Start date Start date
A

Amjad

Hi,
I'm working on an application that sends and receives
data over the serial port using the MSComm control.

How do I empty the buffer of the received data and how do
I set its size? Are there any limits?

Amjad
 
Hi,

You can empty the input buffer by assigning it to a variable (InputLen = 0).
Example,

Dim Buffer As String
Buffer = MSComm1.Input 'this reads and clears the input buffer

Or:
MSComm1.InBufferCount = 0 'clears without reading

You control buffer size using the InBufferSize property controls the maximum
number of characters (bytes) that will be buffered by MSComm.

Dick
--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
Edition ISBN 1-890422-27-4 (391 pages) published February 2002.
 
Thanks.
Every time I use the MSComm1.InBufferSize property I get
an exception error! Do you know why?
for e.g. : MSComm1.InBufferSize = 4096

Other MSComm properties work fine.
PS. I'm trying to download data from a text file (>200KB)
using the serial port. For this purpose I wrote the
following loop which doesn't get all the data!
Do
buffer = MSComm1.Input
received += buffer
Loop Until InStr(buffer, "ok")
 
Back
Top