Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 172
  • Last Modified:

Serial port reading data trouble

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?
1 Solution
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
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

Tom_HickersonAuthor Commented:
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.


Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now