|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Newbe help with Receive Serial Data FunctionI'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 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. -- Show quoteHide quoteScott "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 > 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 Show quoteHide quote "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 > |
|||||||||||||||||||||||