Solved

Tell me how to read serial port!

Posted on 1998-07-15
5
348 Views
Last Modified: 2008-02-01
            When moden is communicating with other hosts,how can I read data from serial port? best to give me  source code for example,thank you!
0
Comment
Question by:dys
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 1

Expert Comment

by:khaledc
ID: 1465916
dys,
You have to use a MSCOMM control (or MSCOMM AcriveX control), the following will answer your question:
The following simple example shows basic serial communications using a modem:

Private Sub Form_Load ()
      ' Buffer to hold input string
      Dim Instring As String
      ' Use COM1.
      MSComm1.CommPort = 1
      ' 9600 baud, no parity, 8 data, and 1 stop bit.
      MSComm1.Settings = "9600,N,8,1"
      ' Tell the control to read entire buffer when Input
      ' is used.
      MSComm1.InputLen = 0
      ' Open the port.
      MSComm1.PortOpen = True
      ' Send the attention command to the modem.
      MSComm1.Output = "AT" + Chr$(13)
      ' Wait for data to come back to the serial port.

Do
            DoEvents
      Loop Until MSComm1.InBufferCount >= 2
      ' Read the "OK" response data in the serial port.
      Instring = MSComm1.Input
      ' Close the serial port.
      MSComm1.PortOpen = False
End Sub

Note   The MSComm control can use polling or an event-driven method to retrieve data from the port. This simple example uses the polling method. For an example of the event-driven method, see help for the OnComm event.

This is how to read data from a serial port.

You can also check the VB help under "MSComm Control"

Best of luck.

0
 
LVL 1

Expert Comment

by:khaledc
ID: 1465917
On more thing I forgot to mention
Do not forget that you have to insert a MSComm Control from VB Prefrences (position your mouth over the toolbox and click on the right hand button of the mouse, from the pull down menu click on "Components" , find and tick "Microsoft Comm Control").
Then insert an Comm control on your form.
Have fun
0
 
LVL 1

Accepted Solution

by:
khaledc earned 50 total points
ID: 1465918
dys
You should give why the answer has been rejected when you unlock the quesiton
Regards
0
 
LVL 1

Expert Comment

by:khaledc
ID: 1465919
dys
The above example works for sure, because I simply tried it myself

0
 
LVL 1

Expert Comment

by:JayMerritt
ID: 1465920
I think he is looking for a way to peek at a connection that is already open.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question