Results 1 to 3 of 3

Thread: Separate data coming from Serial Port

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2016
    Posts
    8

    Separate data coming from Serial Port

    Hi,

    what is the best way wherein I can separate the incoming data from the Serial port?
    The serial port (from Arduino) will throw data to VB in a form something like this:

    2.00
    26.7
    67.8

    If I just put the data in an array, it will just store the three data in a single element, right? I was wondering how can I separate the 2.00, 26.7, and 67.8 from one another?

    Thank you.

  2. #2
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,294

    Re: Separate data coming from Serial Port

    If you're using println on the Arduino to print each value, then you should be able to use readline on the VB6 side to read each value separately from the serial port.
    What you do with each separate value as you get it is up to you at that point.
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  3. #3
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Posts
    3,029

    Re: Separate data coming from Serial Port

    Here is an MSComm control generic OnComm event implementation:

    Code:
    Private Sub MSComm1_OnComm()
        Dim sInput          As String
        
        With MSComm1
            If .CommEvent = comEvReceive Then
                If .InputMode = comInputModeText Then
                    sInput = .Input
                Else
                    sInput = StrConv(.Input, vbUnicode)
                End If
                m_sReceived = m_sReceived & sInput
            End If
        End With
    End Sub
    Notice that input is *always* appended to a buffering member variable m_sReceived before being analyzed.

    You'll need some string handling routines like InStr, Mid, Split, etc. to implement actual m_sReceived parsing but don't get tempted to parse sInput directly as all serial communication can get chunked at random places (i.e. in the middle of your 2.00 transmission).

    Here is a digital weighing scales project of mine which has several such protocols parsed incl. opening serial port, listening for input and parsing input from several devices simultaneously.

    cheers,
    </wqw>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width