Solved

Tell me how to read serial port!

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

777 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