Serial Comm Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alvatar
    New Member
    • Mar 2008
    • 1

    Serial Comm Help

    I am doing a project on microcontroller s and want to be able to send and receive data via RS232 serial cable.
    Right now, my PIC microcontroller code is able to send string data to the computer and HyperTerminal will output the strings. However, in order to manipulate such data I found out that Visual Basic is needed.
    So I tried creating a basic Visual Basic window application using VB Express 2008 just to read bytes sent from serial, using source codes I found in the Internet.

    Basically, the program consists of just a Button and a TextBox. If I click the button, then the program will output anything that is sent from the PIC.

    This is my VB code.

    Imports System.IO.Ports
    Public Class Form1

    Private Sub TextBox1_TextCh anged(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles

    TextBox1.TextCh anged

    End Sub

    Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click
    Dim returnStr As String = ""
    Using com1 As IO.Ports.Serial Port = _
    My.Computer.Por ts.OpenSerialPo rt("COM1", 4800, 0, 8, 1)
    Do
    Dim Incoming As String = com1.ReadLine()
    If Incoming Is Nothing Then
    Exit Do
    Else
    returnStr &= Incoming & vbCrLf
    End If
    Loop
    End Using
    TextBox1.Text = returnStr
    End Sub
    End Class


    However, the program was not able to output anything when I tried debugging mode. After clicking the button, the application seemed to be frozen and could not close normally unless I stop debugging.
    Any help would be greatly appreciated.
Working...