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
Solved

Program to read Data From Comm Port

Posted on 2003-12-04
8
462 Views
Last Modified: 2010-05-01
Hello ,
         I am trying to receive data from serial port
( RS232) COMM2 .Give me some ideas to program to get data and to display them.

Thankyou
Karthick
0
Comment
Question by:karthick2083
8 Comments
 
LVL 11

Expert Comment

by:bingie
ID: 9877200
For a full code tutorial on reading to and sending from the com port:

   http://www.freevbcode.com/ShowCode.Asp?ID=2236

A good tutorial on the MScomm control:

   http://www.yes-tele.com/mscomm.html

******************************************************************************
You have to make certain that both terminals are configured for the same Baud Rate, Number Of Stop Bits, Number Of Data Bits and Parity Bits. With this not set right, Baud rate mismatch, data mismatch or parity error can occur. This is done with the VB code.

When using the MScomm control, you need to set the properties:

Private Sub Form_Load()
    MSComm1.CommPort = 1                  'CommPort to use
    MSComm1.Settings = "9600,N,8,1"     'Setting BaudRate, Parity (Yes, No, Even), Number of Data Bit, Number of Stop Bits
    MSComm1.InputLen = 0                
    MSComm1.PortOpen = True               'Open the port
End Sub

Private Sub Form_Unload(Cancel As Integer)
    MSComm1.PortOpen = False               'Close the port on form Unload
End Sub

To read from the port:

Private Sub MSComm1_OnComm()
 Dim buffer As Variant
 Select Case MSComm1.CommEvent
  Case comEvReceive
  buffer = MSComm1.Input
  Text1.Text = Text1.Text & buffer
 End Select
End Sub

To send from the port:

Private Sub cmdSend_Click()
 MSComm1.Output = "000000001" + chr$(13) 'chr$(13) is used as a carrige return not necessary somtimes
End Sub

You might also need a null modem cable to simulate the handshaking signals, for proper communication. The null modem is connected to facilitate the connection of 2 "DTE" or 2 "DCE". The cable wiring is important, here is some info on that:

http://www.loop-back.com/null-mod.html
http://www.nullmodem.com/NullModem.htm

Diagrams:

http://www.beckwithelectric.com/relays/m3420/commapp/images/ca_fig05.gif
http://goforit.unk.edu/datacomm/images/dc_00oe.gif
http://www.qsl.net/wb3afl/graphics/nullmdm.gif

To ensure it's done correctly, you can buy pre-made null modem cables, as well as connectors for around $1.50. Check this site for info

http://www.national-tech.com/catalog/nullmodemcables.htm
http://www.trianglecables.com/nulmodad.html



Bingie
0
 
LVL 11

Expert Comment

by:bingie
ID: 9877277
As for displaying the data, how do you want to do this? Chart form table text box?

You can VB / Excel OLE automation :

HOWTO: Create Excel Chart w/OLE Automation from Visual Basic
http://support.microsoft.com/default.aspx?scid=KB;en-us;q142387

Excel Automation:
Controlling Excel from a Visual Basic Application
http://www.msofficemag.net/features/2001/06/vba200106wf_f/vba200106wf_f.asp

You can also use the chart control:

http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q275649&ID=KB;EN-US;Q275649&sd=msdn&
http:Q_20361968.html





0
 
LVL 1

Expert Comment

by:MsLim
ID: 9879119
participate
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 
LVL 11

Expert Comment

by:bingie
ID: 9998981
Any Luck??
0
 
LVL 29

Expert Comment

by:leonstryker
ID: 10267532
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

PAQ/No Refund
 
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

leonstryker
EE Cleanup Volunteer
0
 
LVL 11

Expert Comment

by:bingie
ID: 10267685
Leon,

I think i provided more than enough information on what the asker required.

bingie
VB Page Editor
Experts Exchange
0
 
LVL 29

Expert Comment

by:leonstryker
ID: 10267766
bingie,

I agree, but I have no way to test it and the asker did not reply to your posts.

leonstryker
EE Cleanup Volunteer
0
 

Accepted Solution

by:
SpazMODic earned 0 total points
ID: 10327556
PAQed - no points refunded (of 500)

SpazMODic
EE Moderator
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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…

829 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