?
Solved

MSComm (VB6) unable to convert data.. please help!

Posted on 2003-03-05
5
Medium Priority
?
260 Views
Last Modified: 2008-02-01
Hi Everyone!

Im doing a project for my Uni which requires me to connect a simple monitoring unit with a computer. The incoming "streaming" data to the rs232 is of the following format:

'S' A1H A1L A2H A2L....... A5L Dig_IPS, chksum etc

Using the mscomms code provided by microsoft as shown below, I get jibberish (unreadble characters) is there anmy way i can convert them to binary or hex so i can actually read them?:

Option Explicit
Private Sub Form_Load()
         Form1.Caption = "Incoming Data From PIMEX Unit"
         With MSComm1
            'Comm Port Used
            .CommPort = 1
            'Handshaking Settings
            .Handshaking = 0
            'This procedure sets the RThreshold property, which determines
            'how many bytes can arrive at the receive buffer before the OnComm
            'event is triggered and the CommEvent property is set to comEvReceive.
            .RThreshold = 1
            'Determines whether to enable the Request To Send line.
            .RTSEnable = True
            'Sets/returns the baud rate, parity, data bit, and stop bit parameters.
            .Settings = "4800,n,8,1"
            'Sets/returns the minimum number of characters allowable in the transmit.
            .SThreshold = 1
            'Sets/returns the state of the communications port (open or closed).
            .PortOpen = True
            'Leave all other settings as default values.
         End With
         Text1.Text = ""
      End Sub


Private Sub Form_Unload(Cancel As Integer)
MSComm1.PortOpen = False
End Sub

Private Sub MSComm1_OnComm()
Dim InBuff As String

         Select Case MSComm1.CommEvent
         ' Handle each event or error by placing
         ' code below each case statement.

         ' This template is found in the Example
         ' section of the OnComm event Help topic
         ' in VB Help.

         ' Errors
            Case comEventBreak   ' A Break was received.
            Case comEventCDTO    ' CD (RLSD) Timeout.
            Case comEventCTSTO   ' CTS Timeout.
            Case comEventDSRTO   ' DSR Timeout.
            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.
               InBuff = MSComm1.Input
               Call HandleInput(InBuff)
            Case comEvSend ' There are SThreshold number of
                           ' characters in the transmit buffer.
            Case comEvEOF  ' An EOF character was found in the
                           ' input stream.
         End Select

End Sub
      Sub HandleInput(InBuff As String)
         ' This is where you will process your input. This
         ' includes trapping characters, parsing strings,
         ' separating data fields, etc. For this case, you
         ' are simply going to display the data in the TextBox.
         Text1.SelStart = Len(Text1.Text)
         Text1.SelText = InBuff
     
        ' If (Text1 = "s") Then
         '      Text2.Text = "s"
          '     End If
     
    End Sub

0
Comment
Question by:yugant
[X]
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
5 Comments
 

Expert Comment

by:prakrithk
ID: 8081632
Hi,

In the event handler,

Before opening the port
you need to this property along with the
others
...
MSComm1.InputMode = comInputModeBinary
...
Private Sub MSComm1_OnComm()

Dim inbuff as variant
dim mybytearray() as byte

Select Case MSComm1.CommEvent
...
...
...
Case comEvReceive ' Received RThreshold # of chars.
InBuff = MSComm1.Input

ReDim mybytearray(MSComm1.InBufferCount)

'print the array
for i = 0 to MSComm1.InBufferCount - 1
    debug.print Hex(mybytearray(i))
next
...
end select

end sub
Hope this helps
0
 

Expert Comment

by:deepee
ID: 8086330
I think you can also check the COM PORT settigs once again eg. Baud rate, stop bit etc.
0
 

Expert Comment

by:CleanupPing
ID: 8900611
yugant:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 9074071
yugant, an EE Moderator will handle this for you.
Moderator, my recommended disposition is:

    Save as PAQ -- No Refund.

DanRollins -- EE database cleanup volunteer
0
 

Accepted Solution

by:
YensidMod earned 0 total points
ID: 9165900
Question is PAQ'd and no points refunded.

YensidMod
Community Support Moderator @Experts Exchange
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
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…
Suggested Courses
Course of the Month11 days, 18 hours left to enroll

752 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