Solved

Tell me how to read serial port!

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access query that references subform 5 43
Access 2013 combo box not working 3 38
vb6 connector to mongodb 2 51
vbModal 12 37
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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

895 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

13 Experts available now in Live!

Get 1:1 Help Now