CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 8 1234 ... LastLast
Results 1 to 15 of 107
  1. #1
    Join Date
    Jun 2010
    Posts
    41

    recieving 3 value in uart

    Can someone help me with the sourcecode?

  2. #2
    Join Date
    May 2010
    Posts
    12

    Re: recieving 3 value in uart

    Maybe. If you first post the Code you need help with...

  3. #3
    Join Date
    Jun 2010
    Posts
    41

    Re: recieving 3 value in uart

    I want to receive 3 values and display it in VB can you help with the source code, an example code will help

  4. #4
    Join Date
    Jun 2010
    Posts
    41

    Re: recieving 3 value in uart

    I have no idead on the code because I dont know how to do vb6 with serial communication. where to start? how to use mscomm?

  5. #5
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: recieving 3 value in uart

    google will get you several examples as will a search of this site
    Always use [code][/code] tags when posting code.

  6. #6
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: recieving 3 value in uart

    To receive serial input you have to use the MSComm control.
    You go to Project->Components and add 'Microsoft Comm Control 6.0' to your toolbox.
    Now you have MSComm available and can put one to your Form for usage.
    Check the parameters and settings.
    To receive characters you set the .RThreshold property to 1.
    This has the effect that for every received character the OnComm() event of the control will fire.
    Assume your control is Named MSComm1, then you might use this very basic code to receive characters:
    Code:
    Private Sub MSComm1_OnComm()
      Static a$
      a$ = a$ + MSComm1.Input
      If Len(a$) = 3 Then
         debug.print a$
         a$=""
      End If
    End Sub
    Instread of debug.print a$ you would probably do something else with the three received characters.

  7. #7
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: recieving 3 value in uart

    Don't forget to either check the oncomm to see why it fired or check the inbuffercount before issuing the input command otherwise you could be trying to read when there is nothing there to read.
    Always use [code][/code] tags when posting code.

  8. #8
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: recieving 3 value in uart

    Yes. That'd be the next step of higher sophistication using a Select Case to react on distinct reasons of the OnComm() to have fired.

    But the above simple code still would work fine. If there is no .Input available, well, then there is none. It will wait for the next valid character, until they are three.

  9. #9
    Join Date
    Jun 2010
    Posts
    41

    Re: recieving 3 value in uart

    What I mean is that I will receive 3 different values in uart in ASCII and convert each of them to another value. Is the code still fit? or it needs a modification

    And also the value that I will be receiving comes from a source that keeps on transmitting.
    Last edited by feitanx; June 5th, 2010 at 08:08 AM.

  10. #10
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: recieving 3 value in uart

    Depends on how you are sending them. If you can put a \ character in between each part, you could receive one packet and split it up
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  11. #11
    Join Date
    Jun 2010
    Posts
    41

    Re: recieving 3 value in uart

    I'am sending them in different line. Like:

    342
    345
    423

    I use the this format in sending. I would like to assign variable to each of them.

  12. #12
    Join Date
    Jun 2010
    Posts
    41

    Re: recieving 3 value in uart

    OR should I send the data in this format 345\324\435?
    PLease help

  13. #13
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: recieving 3 value in uart

    Here's a sample for you.
    Attached Files Attached Files
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  14. #14
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: recieving 3 value in uart

    If you are able to send this format
    234/345/456
    123/345/678
    everything is rather easy, provided you send complete lines with 3 numbers each.
    After the third number a vbCrLf must be sent to definitely delimit a group of 3 numbers.
    In OnComm you can do then:
    Code:
    Private Num1%, Num2%, Num3%
    Private RLine$
    Private Sub MSComm1_OnComm()
      RLine = RLine + MSComm1.Input
      If Len(RLine>2) Then
         If Right(RLine,2) = vbCrLf Then ' a complete record with three numbers has been received now
            dim a$()
            a = Split(RLine, "/") 'split the line into the three numbers
            Num1 = a(0) 'get first number
            Num2 = a(1) 'get second number
            Num3 = a(2) 'get third number
            RLine = "" 'reset the receiver variable for the next line
         End If
      End If
    End Sub

  15. #15
    Join Date
    Jun 2010
    Posts
    41

    Re: recieving 3 value in uart

    WHAT is VbCrlf? I'am receiving it from a micro-controller with c programming.
    Last edited by feitanx; June 9th, 2010 at 08:47 AM.

Page 1 of 8 1234 ... LastLast

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

Featured