Addressing a serial port from within visual basic .NET

Q

Q

Hello you all,

I have to create an application which writes data to a serial port, waits
for an answer and read this answer from the same
serial port.

I just don't know where to start.

Any suggestions?????
Some code snippets would be very helpfull!!!

Tks in advance,

Q
 
D

Dick Grier

Hi,

I have a number of examples for this sort of thing in my book. See below.

Suggested steps.

1. Download DesktopSerialIO from my homepage.
2. Set the CommPort, BitRate, (etc.) properties
3. Set PortOpen = True
4. Send a command using the Output method
5. Wait in an Application.DoEvents loop until the reply has been received.
Inside the loop you can use the InputString method to append newly received
data to a string buffer, and you can look into that buffer (using SubString
or InStr, for example) to see of all of the data is there. When it is, exit
the loop. You can add a timeout check in the loop, if needed.
6. Process the buffered data.

There are other way to tackle this, but a simple loop often is best --
because it is simple AND fast.

Total code? Perhaps 10-15 lines.

Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 4th
Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See
www.mabry.com/vbpgser4 to order.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top