RS232 Anyone???

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

    RS232 Anyone???

    I'm trying to use the RS232 class that was in the Platform SDK (i think).
    Has anyone else used this with events successfully? Here's what i've got:
    =============== =======
    Public WithEvents bbsPort As Rs232 = New Rs232

    With bbsPort
    .BaudRate = baud
    .DataBit = dataBits
    .Parity = parity
    .Port = comPort
    .StopBit = stopBits
    Try
    .Open()
    Catch ex As Exception
    StopServerToolS tripMenuItem.Pe rformClick()
    MsgBox(ex.Messa ge, MsgBoxStyle.Cri tical)
    End Try
    End With

    'The port opens okay because if I have another application using the port I
    get the exception message "Unable to open COM1"

    Public Sub ReadComPort(ByV al Source As Rs232, ByVal DataBuffer() As Byte)
    Handles bbsPort.DataRec eived
    MsgBox("DataRec eived")
    End Sub
    =============== ========

    Two questions I have are: I know I can communicate because I can talk to
    the serial device with Hyperterminal. When I try it with my app, the event
    is never fired. So I must be doing something wrong. Any help is
    desperately needed & appreciated.

    Second question: There doesn't seem to be a way to set flow control. Has
    anyone added flow control capabilities to this class?

    Thanks.


  • Terry Olsen

    #2
    Re: RS232 Anyone???

    Nevermind....I just found out that VB 2005 supports the serial ports.
    Changed my code and all works fine now...


    "Terry Olsen" <tolsen64@hotma il.com> wrote in message
    news:%23CxG6e5k EHA.3912@TK2MSF TNGP12.phx.gbl. ..[color=blue]
    > I'm trying to use the RS232 class that was in the Platform SDK (i think).
    > Has anyone else used this with events successfully? Here's what i've got:
    > =============== =======
    > Public WithEvents bbsPort As Rs232 = New Rs232
    >
    > With bbsPort
    > .BaudRate = baud
    > .DataBit = dataBits
    > .Parity = parity
    > .Port = comPort
    > .StopBit = stopBits
    > Try
    > .Open()
    > Catch ex As Exception
    > StopServerToolS tripMenuItem.Pe rformClick()
    > MsgBox(ex.Messa ge, MsgBoxStyle.Cri tical)
    > End Try
    > End With
    >
    > 'The port opens okay because if I have another application using the port
    > I get the exception message "Unable to open COM1"
    >
    > Public Sub ReadComPort(ByV al Source As Rs232, ByVal DataBuffer() As Byte)
    > Handles bbsPort.DataRec eived
    > MsgBox("DataRec eived")
    > End Sub
    > =============== ========
    >
    > Two questions I have are: I know I can communicate because I can talk to
    > the serial device with Hyperterminal. When I try it with my app, the
    > event is never fired. So I must be doing something wrong. Any help is
    > desperately needed & appreciated.
    >
    > Second question: There doesn't seem to be a way to set flow control. Has
    > anyone added flow control capabilities to this class?
    >
    > Thanks.
    >
    >[/color]


    Comment

    • One Handed Man \( OHM - Terry Burns \)

      #3
      Re: RS232 Anyone???

      2005 is not released yet, so if your planning this for a production target
      you may be leaving yourself with a problem if they take out the support on
      the release version.

      --

      OHM ( Terry Burns )
      . . . One-Handed-Man . . .
      If U Need My Email ,Ask Me

      Time flies when you don't know what you're doing

      "Terry Olsen" <tolsen64@hotma il.com> wrote in message
      news:uiBBnC7kEH A.3608@TK2MSFTN GP09.phx.gbl...[color=blue]
      > Nevermind....I just found out that VB 2005 supports the serial ports.
      > Changed my code and all works fine now...
      >
      >
      > "Terry Olsen" <tolsen64@hotma il.com> wrote in message
      > news:%23CxG6e5k EHA.3912@TK2MSF TNGP12.phx.gbl. ..[color=green]
      > > I'm trying to use the RS232 class that was in the Platform SDK (i[/color][/color]
      think).[color=blue][color=green]
      > > Has anyone else used this with events successfully? Here's what i've[/color][/color]
      got:[color=blue][color=green]
      > > =============== =======
      > > Public WithEvents bbsPort As Rs232 = New Rs232
      > >
      > > With bbsPort
      > > .BaudRate = baud
      > > .DataBit = dataBits
      > > .Parity = parity
      > > .Port = comPort
      > > .StopBit = stopBits
      > > Try
      > > .Open()
      > > Catch ex As Exception
      > > StopServerToolS tripMenuItem.Pe rformClick()
      > > MsgBox(ex.Messa ge, MsgBoxStyle.Cri tical)
      > > End Try
      > > End With
      > >
      > > 'The port opens okay because if I have another application using the[/color][/color]
      port[color=blue][color=green]
      > > I get the exception message "Unable to open COM1"
      > >
      > > Public Sub ReadComPort(ByV al Source As Rs232, ByVal DataBuffer() As[/color][/color]
      Byte)[color=blue][color=green]
      > > Handles bbsPort.DataRec eived
      > > MsgBox("DataRec eived")
      > > End Sub
      > > =============== ========
      > >
      > > Two questions I have are: I know I can communicate because I can talk[/color][/color]
      to[color=blue][color=green]
      > > the serial device with Hyperterminal. When I try it with my app, the
      > > event is never fired. So I must be doing something wrong. Any help is
      > > desperately needed & appreciated.
      > >
      > > Second question: There doesn't seem to be a way to set flow control.[/color][/color]
      Has[color=blue][color=green]
      > > anyone added flow control capabilities to this class?
      > >
      > > Thanks.
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Cor Ligthert

        #4
        Re: RS232 Anyone???

        Hi Terry,
        [color=blue]
        > 2005 is not released yet, so if your planning this for a production target
        > you may be leaving yourself with a problem if they take out the support on
        > the release version.
        >[/color]

        A very good answer to Terry and in general.

        :-)

        Cor


        Comment

        • Terry Olsen

          #5
          Re: RS232 Anyone???

          It's a personal project.

          "One Handed Man ( OHM - Terry Burns )" <news.microsoft .com> wrote in message
          news:u5Y%23NI%2 3kEHA.3984@TK2M SFTNGP14.phx.gb l...[color=blue]
          > 2005 is not released yet, so if your planning this for a production target
          > you may be leaving yourself with a problem if they take out the support on
          > the release version.
          >[/color]


          Comment

          • One Handed Man \( OHM - Terry Burns \)

            #6
            Re: RS232 Anyone???

            The logic stands, however, its obviously your call.

            --

            OHM ( Terry Burns )
            . . . One-Handed-Man . . .
            If U Need My Email ,Ask Me

            Time flies when you don't know what you're doing

            "Terry Olsen" <tolsen64@hotma il.com> wrote in message
            news:esH1JzBlEH A.556@tk2msftng p13.phx.gbl...[color=blue]
            > It's a personal project.
            >
            > "One Handed Man ( OHM - Terry Burns )" <news.microsoft .com> wrote in[/color]
            message[color=blue]
            > news:u5Y%23NI%2 3kEHA.3984@TK2M SFTNGP14.phx.gb l...[color=green]
            > > 2005 is not released yet, so if your planning this for a production[/color][/color]
            target[color=blue][color=green]
            > > you may be leaving yourself with a problem if they take out the support[/color][/color]
            on[color=blue][color=green]
            > > the release version.
            > >[/color]
            >
            >[/color]


            Comment

            • DraguVaso

              #7
              Re: RS232 Anyone???

              Hi Terry,

              I'm planning to make anapplication that has to communicate with an SMS
              Modem. I kind of drawned in the lots of bad RS232 code I foudn and tested.

              I'm also tempted to do it in VS 2005 because I heard it was integrated
              there. Does your code works fine? And did you use the VS 2005 Beta 1 or the
              VS 2005 Express Edition? Is it possible to make a working Service with it
              that uses RS232?

              If you woudl be so kind to paste your code that would be very helpfulltoo
              :-)

              Thanks a lot in advance,

              Pieter

              "Terry Olsen" <tolsen64@hotma il.com> wrote in message
              news:uiBBnC7kEH A.3608@TK2MSFTN GP09.phx.gbl...[color=blue]
              > Nevermind....I just found out that VB 2005 supports the serial ports.
              > Changed my code and all works fine now...
              >
              >
              > "Terry Olsen" <tolsen64@hotma il.com> wrote in message
              > news:%23CxG6e5k EHA.3912@TK2MSF TNGP12.phx.gbl. ..[color=green]
              > > I'm trying to use the RS232 class that was in the Platform SDK (i[/color][/color]
              think).[color=blue][color=green]
              > > Has anyone else used this with events successfully? Here's what i've[/color][/color]
              got:[color=blue][color=green]
              > > =============== =======
              > > Public WithEvents bbsPort As Rs232 = New Rs232
              > >
              > > With bbsPort
              > > .BaudRate = baud
              > > .DataBit = dataBits
              > > .Parity = parity
              > > .Port = comPort
              > > .StopBit = stopBits
              > > Try
              > > .Open()
              > > Catch ex As Exception
              > > StopServerToolS tripMenuItem.Pe rformClick()
              > > MsgBox(ex.Messa ge, MsgBoxStyle.Cri tical)
              > > End Try
              > > End With
              > >
              > > 'The port opens okay because if I have another application using the[/color][/color]
              port[color=blue][color=green]
              > > I get the exception message "Unable to open COM1"
              > >
              > > Public Sub ReadComPort(ByV al Source As Rs232, ByVal DataBuffer() As[/color][/color]
              Byte)[color=blue][color=green]
              > > Handles bbsPort.DataRec eived
              > > MsgBox("DataRec eived")
              > > End Sub
              > > =============== ========
              > >
              > > Two questions I have are: I know I can communicate because I can talk[/color][/color]
              to[color=blue][color=green]
              > > the serial device with Hyperterminal. When I try it with my app, the
              > > event is never fired. So I must be doing something wrong. Any help is
              > > desperately needed & appreciated.
              > >
              > > Second question: There doesn't seem to be a way to set flow control.[/color][/color]
              Has[color=blue][color=green]
              > > anyone added flow control capabilities to this class?
              > >
              > > Thanks.
              > >
              > >[/color]
              >
              >[/color]


              Comment

              • Terry Olsen

                #8
                Re: RS232 Anyone???

                I'm using the Express version Beta 1 downloadable from Microsoft.

                I don't have too much in the way of functionality yet as my time to work on
                it is very limited. But it's pretty straight forward. When you install the
                Express version, you also get the MSDN library that goes with it..so it's
                all in the docs. But here are some snippets of what I have so far...it
                receives input from the COM port using a ReceivedEvent and throws up a
                messagebox with the received character.


                Imports System.IO.Ports
                Public WithEvents bbsPort As SerialPort = New SerialPort

                For Each sp As String In My.Computer.Por ts.SerialPortNa mes
                If IsPortAvailable (sp) Then cboComPort.Item s.Add(sp)
                Next

                Public Function IsPortAvailable (ByVal port As String) As Boolean
                ' This function attempts to open the passed Comm Port. If it is
                ' available, it returns True, else it returns False. To determine
                ' availability a Try-Catch block is used.
                Try
                bbsPort.PortNam e = port
                bbsPort.Open()
                ' If it makes it to here, then the Comm Port is available.
                bbsPort.Close()
                Return True
                Catch
                ' If it gets here, then the attempt to open the Comm Port
                ' was unsuccessful.
                Return False
                End Try
                End Function

                With bbsPort
                .BaudRate = baud
                .DataBits = dataBits
                .Parity = parity
                .PortName = comPort
                .StopBits = stopBits
                .Handshake = flowControl
                .ReceivedBytesT hreshold = 1
                Try
                .Open()
                Catch ex As Exception
                StopServerToolS tripMenuItem.Pe rformClick()
                MsgBox(ex.Messa ge, MsgBoxStyle.Cri tical, "Telnet2BBS ")
                End Try
                End With

                Public Sub ReadComPort(ByV al Sender As Object, ByVal e As
                System.IO.Ports .SerialReceived EventArgs) Handles bbsPort.Receive dEvent
                Try
                MsgBox(Chr(bbsP ort.ReadByte))
                Catch ex As Exception
                Exit Sub
                End Try
                End Sub

                "DraguVaso" <pietercoucke@h otmail.com> wrote in message
                news:%235qe0dYl EHA.2020@TK2MSF TNGP09.phx.gbl. ..[color=blue]
                > Hi Terry,
                >
                > I'm planning to make anapplication that has to communicate with an SMS
                > Modem. I kind of drawned in the lots of bad RS232 code I foudn and tested.
                >
                > I'm also tempted to do it in VS 2005 because I heard it was integrated
                > there. Does your code works fine? And did you use the VS 2005 Beta 1 or
                > the
                > VS 2005 Express Edition? Is it possible to make a working Service with it
                > that uses RS232?
                >
                > If you woudl be so kind to paste your code that would be very helpfulltoo
                > :-)[/color]


                Comment

                • DraguVaso

                  #9
                  Re: RS232 Anyone???

                  Thanks! I'm gona try to download it and play a bit arround!
                  :-)

                  "Terry Olsen" <tolsen64@hotma il.com> wrote in message
                  news:OfpNFPclEH A.3876@TK2MSFTN GP15.phx.gbl...[color=blue]
                  > I'm using the Express version Beta 1 downloadable from Microsoft.
                  >
                  > I don't have too much in the way of functionality yet as my time to work[/color]
                  on[color=blue]
                  > it is very limited. But it's pretty straight forward. When you install[/color]
                  the[color=blue]
                  > Express version, you also get the MSDN library that goes with it..so it's
                  > all in the docs. But here are some snippets of what I have so far...it
                  > receives input from the COM port using a ReceivedEvent and throws up a
                  > messagebox with the received character.
                  >
                  >
                  > Imports System.IO.Ports
                  > Public WithEvents bbsPort As SerialPort = New SerialPort
                  >
                  > For Each sp As String In My.Computer.Por ts.SerialPortNa mes
                  > If IsPortAvailable (sp) Then cboComPort.Item s.Add(sp)
                  > Next
                  >
                  > Public Function IsPortAvailable (ByVal port As String) As Boolean
                  > ' This function attempts to open the passed Comm Port. If it is
                  > ' available, it returns True, else it returns False. To determine
                  > ' availability a Try-Catch block is used.
                  > Try
                  > bbsPort.PortNam e = port
                  > bbsPort.Open()
                  > ' If it makes it to here, then the Comm Port is available.
                  > bbsPort.Close()
                  > Return True
                  > Catch
                  > ' If it gets here, then the attempt to open the Comm Port
                  > ' was unsuccessful.
                  > Return False
                  > End Try
                  > End Function
                  >
                  > With bbsPort
                  > .BaudRate = baud
                  > .DataBits = dataBits
                  > .Parity = parity
                  > .PortName = comPort
                  > .StopBits = stopBits
                  > .Handshake = flowControl
                  > .ReceivedBytesT hreshold = 1
                  > Try
                  > .Open()
                  > Catch ex As Exception
                  > StopServerToolS tripMenuItem.Pe rformClick()
                  > MsgBox(ex.Messa ge, MsgBoxStyle.Cri tical, "Telnet2BBS ")
                  > End Try
                  > End With
                  >
                  > Public Sub ReadComPort(ByV al Sender As Object, ByVal e As
                  > System.IO.Ports .SerialReceived EventArgs) Handles bbsPort.Receive dEvent
                  > Try
                  > MsgBox(Chr(bbsP ort.ReadByte))
                  > Catch ex As Exception
                  > Exit Sub
                  > End Try
                  > End Sub
                  >
                  > "DraguVaso" <pietercoucke@h otmail.com> wrote in message
                  > news:%235qe0dYl EHA.2020@TK2MSF TNGP09.phx.gbl. ..[color=green]
                  > > Hi Terry,
                  > >
                  > > I'm planning to make anapplication that has to communicate with an SMS
                  > > Modem. I kind of drawned in the lots of bad RS232 code I foudn and[/color][/color]
                  tested.[color=blue][color=green]
                  > >
                  > > I'm also tempted to do it in VS 2005 because I heard it was integrated
                  > > there. Does your code works fine? And did you use the VS 2005 Beta 1 or
                  > > the
                  > > VS 2005 Express Edition? Is it possible to make a working Service with[/color][/color]
                  it[color=blue][color=green]
                  > > that uses RS232?
                  > >
                  > > If you woudl be so kind to paste your code that would be very[/color][/color]
                  helpfulltoo[color=blue][color=green]
                  > > :-)[/color]
                  >
                  >[/color]


                  Comment

                  Working...