Solved

Tell me how to read serial port!

Posted on 1998-07-15
5
319 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
  • 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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 …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now