Newbe help with Receive Serial Data Function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ken

    Newbe help with Receive Serial Data Function

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

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

    Using com2 As IO.Ports.Serial Port = _
    My.Computer.Por ts.OpenSerialPo rt("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 ReceiveSerialDa ta() As String

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

    Using com2 As IO.Ports.Serial Port = _
    My.Computer.Por ts.OpenSerialPo rt("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.IOExc eption 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

    #2
    RE: Newbe help with Receive Serial Data Function

    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:
    [color=blue]
    > Hello everyone,
    > I'm new to visual VB and I am trying to setup communications using the
    > Function ReceiveSerialDa ta() As String example found in the help
    > section of Microsoft Visual Basic 2005 Express Edition.
    >
    > Sample Code:
    > Function ReceiveSerialDa ta() As String
    > ' Receive strings from a serial port.
    > Dim returnStr As String = ""
    >
    > Using com2 As IO.Ports.Serial Port = _
    > My.Computer.Por ts.OpenSerialPo rt("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 ReceiveSerialDa ta() As String
    >
    > ' Receive strings from a serial port.
    > Dim returnStr As String = ""
    > txtReceive.Text = returnStr
    >
    > Using com2 As IO.Ports.Serial Port = _
    > My.Computer.Por ts.OpenSerialPo rt("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.IOExc eption 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
    >[/color]

    Comment

    • Leo W.

      #3
      RE: Newbe help with Receive Serial Data Function

      Scott,

      Myabe this will help




      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:
      [color=blue]
      > Hello everyone,
      > I'm new to visual VB and I am trying to setup communications using the
      > Function ReceiveSerialDa ta() As String example found in the help
      > section of Microsoft Visual Basic 2005 Express Edition.
      >
      > Sample Code:
      > Function ReceiveSerialDa ta() As String
      > ' Receive strings from a serial port.
      > Dim returnStr As String = ""
      >
      > Using com2 As IO.Ports.Serial Port = _
      > My.Computer.Por ts.OpenSerialPo rt("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 ReceiveSerialDa ta() As String
      >
      > ' Receive strings from a serial port.
      > Dim returnStr As String = ""
      > txtReceive.Text = returnStr
      >
      > Using com2 As IO.Ports.Serial Port = _
      > My.Computer.Por ts.OpenSerialPo rt("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.IOExc eption 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
      >[/color]

      Comment

      Working...