Link to home
Start Free TrialLog in
Avatar of bradbritton
bradbritton

asked on

Issue with serial port in VS 2005

I am making an app that uses a serial port to listen for incoming data, but for some reason I cannot get it to work. It freezes when I click the button to start the app. Any ideas??

Thanks,

Brad

--------------------------------------------------------------------------------------------------------------------------------------------

Imports System.IO


Public Class Form1


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


    End Sub

    Function ReceiveSerialData() As String
        ' Receive strings from a serial port.
        Dim returnStr As String = ""

        Using com4 As IO.Ports.SerialPort = _
                My.Computer.Ports.OpenSerialPort("COM4")
            Do
                Dim Incoming As String = com4.ReadLine()
                If Incoming Is Nothing Then
                    Exit Do
                Else
                    returnStr &= Incoming & vbCrLf
                End If
            Loop
        End Using

        Return returnStr
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ReceiveSerialData()
    End Sub
End Class
ASKER CERTIFIED SOLUTION
Avatar of iHadi
iHadi
Flag of Syrian Arab Republic image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bradbritton
bradbritton

ASKER

hmmmm.... gives me an error about using "With Evernts". I will have to look into this.