I am doing a project on microcontrollers 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_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
TextBox1.TextChanged
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim returnStr As String = ""
Using com1 As IO.Ports.SerialPort = _
My.Computer.Ports.OpenSerialPort("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.