Serial port reading data trouble

Posted on 2005-04-13
Last Modified: 2008-02-01
I have a device that sends data continously over serial.  I have setup a mscomm control that recieves this data and then sends it to a text box.

The data in the text box has a bunch of character chr(127) , little boxes, inserted between the actuall data.  However, when I go into hyperterminal the data is clean.  

This is a sample from hyperteminal

The data I am getting from the mscomm control has a varriing number of chr(127) characters inserted in each number something like...

Hyperterminal is set up 9600,7,e,1 with no handshaking

MScomm1 is set up 9600,7,e,1
DTREnable = True
EOFEnable = True
Handshaking = None
InBufferSize = 1024
InputLen =1
InputMode = 0
NullDiscard = False
ParityReplace = ?
RThreashold =1
RTSEnable = True

If I don't set RTSEnable = True I don't get any data, but I have changed the other settings to no better solution.  My code looks like this...
Private Sub MSComm1_OnComm()
  Text1.Text = Text1.Text & MSComm1.Input
End Sub

Any Ideas?
Question by:Tom_Hickerson
    LVL 38

    Expert Comment

    Is InputMode set to binary?

    Make sure it is, and try:

    Private Sub MSComm1_OnComm()
      Text1.Text = Text1.Text & StrConv(MSComm1.Input, vbUnicode)
    End Sub
    LVL 32

    Accepted Solution

    You should also only read the data in the OnComm event if the CommEvent = comEvReceive

    Here is the prototype from MSDN:

    Private Sub MSComm_OnComm ()
       Select Case MSComm1.CommEvent
       ' Handle each event or error by placing
       ' code below each case statement

       ' Errors
          Case comEventBreak   ' A Break was received.
          Case comEventFrame   ' Framing Error
          Case comEventOverrun   ' Data Lost.
          Case comEventRxOver   ' Receive buffer overflow.
          Case comEventRxParity   ' Parity Error.
          Case comEventTxFull   ' Transmit buffer full.
          Case comEventDCB   ' Unexpected error retrieving DCB]

       ' Events
          Case comEvCD   ' Change in the CD line.
          Case comEvCTS   ' Change in the CTS line.
          Case comEvDSR   ' Change in the DSR line.
          Case comEvRing   ' Change in the Ring Indicator.
          Case comEvReceive   ' Received RThreshold # of
                            ' chars.
          Case comEvSend   ' There are SThreshold number of
                         ' characters in the transmit
                         ' buffer.
          Case comEvEof   ' An EOF charater was found in
                         ' the input stream
       End Select
    End Sub

    LVL 1

    Author Comment

    I had looked at the parity several times, but I still had it set wrong so use to seeing the 9600,n,1 that I never thought about it was suppose to be 9600,e,1.
     The framing error trap helped me find it.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    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!

    If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
    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.
    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…
    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…

    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

    7 Experts available now in Live!

    Get 1:1 Help Now