Read data of a DB9 Serial port

Posted on 2005-04-16
Last Modified: 2008-02-01
I have a machine that sends data to a DB9 Serial port of my PC.

I want to read this data.

How can i read it?

Thanks in advance.

Question by:perfectshark
    LVL 13

    Assisted Solution

    The easiest way to read data from the serial port in VB is to use the MS Comm ocx

    This component reads from the ports buffer and sends data via the port

    See these urls for more information on using this component

    Also you can look up the full explanation of this component in the msdn
    LVL 13

    Accepted Solution

    Yes iHadi is right.... The best and most reliable method is to use MSComm control of VB6
    Go to Project | Components and select "Microsoft Comm Control 6" from the list.... Now add this to your form.....

    Private Sub Form_Load()
    MSComm1.Settings = "4800,n,8,1"      'Change this to your settings....
    MSComm1.CommPort = 1                  'Change this to your port no.
         If mscomm1.portopen=false then
            MSComm1.PortOpen = True
    End Sub

    Private Sub MSComm1_OnComm()
        Select Case MSComm1.CommEvent
            Case comEvReceive   ' Received RThreshold # of chars.        
                text1.seltext = MSComm1.Input          
        End Select
    End Sub

    To run this program you will need a MSComm control and a Textbox on your form.... Please change the multiline property of your Textbox to be true..... This will display what you receive on the comm port in a textbox....

    Imran Arshad
    LVL 1

    Author Comment

    Ok. it works, but it return me "ôññð÷ôüòðòðððó" DATA

    What could be the problem?
    LVL 13

    Expert Comment

    >>What could be the problem?

    Check the Baud Rate. Try it at 9600 or what the documentation of the machine says.... It could be any standard baud rate between 2400 and 115200...

    LVL 13

    Expert Comment

    What is the data you are expecting
    The machine might be sending machine code (binary code) that appears the way you see it

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Introduction This article makes the case for using two modules in your VBA/VB6 applications to provide both case-sensitive and case-insensitive text comparison operations.  Recently, I solved an EE question using the LIKE function.  In order for th…
    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    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…

    760 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

    12 Experts available now in Live!

    Get 1:1 Help Now