Serial Com VB 2010
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Serial Com VB 2010

  1. #1
    Join Date
    Nov 2013
    Posts
    2

    Serial Com VB 2010

    hi guys. i`m new to vb and here to seek advice regarding data received in serial com. i`m trying to make external hardware to control Interface in vb, which is arduino. the thing is, both serial works fine, however when i try to send "1" from arduino (even though when i monitor the serial output, it do came out "1") vb receive higher value which is 255. does the data receive thru serial to vb add up as it receive? i already tried to receive string input, end up the same and sometimes dont even works. what did i do wrong in serial receive? thanks in advanced

    Code:
    Public Class Form1
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            pic1.Visible = False
            pic2.Visible = False
        End Sub
    
        Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click
            SerialPort1.PortName = "com3"
            SerialPort1.BaudRate = 9600
            SerialPort1.Encoding = System.Text.Encoding.Default
            SerialPort1.Open()
            btnOpen.Enabled = False
    
        End Sub
    
        Sub DataReceived()
            Dim receiveData As Integer
    
            receiveData = SerialPort1.ReadChar
    
            txtReceive.Text = receiveData
            If receiveData = 1 Then
                pic1.Visible = True
    
    
            End If
            If receiveData = 2 Then
                pic2.Visible = True
            End If
        End Sub
        Delegate Sub ConnectedCallBack()
        Private Sub SerialPort1_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
            Dim D As New ConnectedCallBack(AddressOf DataReceived)
            Try
                Me.Invoke(D)
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
        End Sub
    End Class

    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,946

    Re: Serial Com VB 2010

    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!

  3. #3
    Join Date
    Nov 2013
    Posts
    2

    Re: Serial Com VB 2010

    Quote Originally Posted by dglienna View Post
    Hi David,
    Thanks

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center