[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Issue with serial port in VS 2005

Posted on 2006-05-16
3
Medium Priority
?
196 Views
Last Modified: 2010-04-23
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
0
Comment
Question by:bradbritton
2 Comments
 
LVL 13

Accepted Solution

by:
iHadi earned 1500 total points
ID: 16695039
Hi
Try this

    Dim returnStr As String = ""

    Private Sub com4_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles com4.DataReceived
        returnStr &= com4.ReadExisting & vbCrLf
    End Sub
0
 

Author Comment

by:bradbritton
ID: 16699739
hmmmm.... gives me an error about using "With Evernts". I will have to look into this.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month18 days, 19 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question