K
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
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