By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,701 Members | 1,955 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,701 IT Pros & Developers. It's quick & easy.

Newbe help with Receive Serial Data Function

P: n/a
ken
Hello everyone,
I'm new to visual VB and I am trying to setup communications using the
Function ReceiveSerialData() As String example found in the help
section of Microsoft Visual Basic 2005 Express Edition.

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

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

Return returnStr
End Function

My modified code:
Function ReceiveSerialData() As String

' Receive strings from a serial port.
Dim returnStr As String = ""
txtReceive.Text = returnStr

Using com2 As IO.Ports.SerialPort = _
My.Computer.Ports.OpenSerialPort("COM2")
Do
Incomingcapture = com2.ReadLine()
If Incomingcapture Is Nothing Then
Exit Do
Else
returnStr &= Incomingcapture & vbCrLf
txtReceive.Text = returnStr
End If
Loop
End Using

Return returnStr
End Function

I have a Garmin gps attached to com2 and I can see the data using
Hyper Terminal. My problem is, with Hyper Terminal disconnected and
running the above code I get:

System.IO.IOException was unhandled
Message="The I/O operation has been aborted because of either a
thread exit or an application request.

I don't know what I'm doing wrong. Can someone explain how I can view
the data coming from the gps or better yet if anyone can post working
code to do this I would be very much appreciative.

Thank you in advance for any and all help.
Best regards,
Ken
Apr 17 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Ken

Did you ever get answer to this problem? I am trying to use the same code
but I am also trying to transmit data over it too and have not been very
successful.
--
Scott
"ken" wrote:
Hello everyone,
I'm new to visual VB and I am trying to setup communications using the
Function ReceiveSerialData() As String example found in the help
section of Microsoft Visual Basic 2005 Express Edition.

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

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

Return returnStr
End Function

My modified code:
Function ReceiveSerialData() As String

' Receive strings from a serial port.
Dim returnStr As String = ""
txtReceive.Text = returnStr

Using com2 As IO.Ports.SerialPort = _
My.Computer.Ports.OpenSerialPort("COM2")
Do
Incomingcapture = com2.ReadLine()
If Incomingcapture Is Nothing Then
Exit Do
Else
returnStr &= Incomingcapture & vbCrLf
txtReceive.Text = returnStr
End If
Loop
End Using

Return returnStr
End Function

I have a Garmin gps attached to com2 and I can see the data using
Hyper Terminal. My problem is, with Hyper Terminal disconnected and
running the above code I get:

System.IO.IOException was unhandled
Message="The I/O operation has been aborted because of either a
thread exit or an application request.

I don't know what I'm doing wrong. Can someone explain how I can view
the data coming from the gps or better yet if anyone can post working
code to do this I would be very much appreciative.

Thank you in advance for any and all help.
Best regards,
Ken

May 22 '06 #2

P: n/a
Scott,

Myabe this will help

http://msdn2.microsoft.com/en-us/library/ms172760.aspx
http://msdn2.microsoft.com/en-us/library/e4560dx9.aspx

I am just using this code to find available ports, diaplay them and then
connect to an available port to capture caller-id data, etc. But I found the
links were enough to get me going. Hope this helps.

Leo

"ken" wrote:
Hello everyone,
I'm new to visual VB and I am trying to setup communications using the
Function ReceiveSerialData() As String example found in the help
section of Microsoft Visual Basic 2005 Express Edition.

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

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

Return returnStr
End Function

My modified code:
Function ReceiveSerialData() As String

' Receive strings from a serial port.
Dim returnStr As String = ""
txtReceive.Text = returnStr

Using com2 As IO.Ports.SerialPort = _
My.Computer.Ports.OpenSerialPort("COM2")
Do
Incomingcapture = com2.ReadLine()
If Incomingcapture Is Nothing Then
Exit Do
Else
returnStr &= Incomingcapture & vbCrLf
txtReceive.Text = returnStr
End If
Loop
End Using

Return returnStr
End Function

I have a Garmin gps attached to com2 and I can see the data using
Hyper Terminal. My problem is, with Hyper Terminal disconnected and
running the above code I get:

System.IO.IOException was unhandled
Message="The I/O operation has been aborted because of either a
thread exit or an application request.

I don't know what I'm doing wrong. Can someone explain how I can view
the data coming from the gps or better yet if anyone can post working
code to do this I would be very much appreciative.

Thank you in advance for any and all help.
Best regards,
Ken

May 23 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.