communication with a serial port

i have a simple serial port connection that i am trying to pass some letters too and get hte response  -- code is as follows:

If MSComm1.PortOpen Then
     MSComm1.PortOpen = False
  End If
 
  MSComm1.Settings = "19200,n,8,1"
  MSComm1.InputLen = 0
  MSComm1.PortOpen = True

 MSComm1.Output = Text2.Text & Chr$(13)
    Do
    DoEvents
    Buffer$ = Buffer$ & MSComm1.Input
    Loop Until InStr(Buffer$, vbCrLf)
 
    Text1.Text = Buffer$

the problem i keep running into is that when it sends information to the serial port i have to click the command button twice to get a response

i got around this by having the portopen stuff in the form load and then the output and information back in the command1 event

how do i have it connect send the ouptput and then get the input all in the command1 click event?
tpiazzaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

teduncanCommented:
Probably what's happening is that the comm's receive buffer already has a CRLF in it before you click the button the first time, so your DO loop reads up to it (maybe it's at the beginning of the buffer?) and exits.  The second time you click the button, it gets the first response up to its CRLF.

If this is the case, you can fix it by emptying the receive buffer immediately right before transmitting.  Put the following lines before your Output line:
Buffer$ = MSComm1.Input
Buffer$ = ""

Hope this helps!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tpiazzaAuthor Commented:
thanks alot
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.