Home All Groups Group Topic Archive Search About

Help needed using sample RS232 class to read from serial port

Author
23 Mar 2006 5:33 AM
Dave Harry
I found the RS232 class from MS's 101 VB samples.

Writing to the port works fine. (I've got hyperterminal on the other comm
port and a crossover cable between COM1 and COM2)
The port is opened with:

    Public switchcom As New Rs232
    switchcom.Open(2, 57600, 8, Rs232.DataParity.Parity_None,
Rs232.DataStopBit.StopBit_1, 512)


But reading is giving me no end of trouble. Since there are no com port
events anymore in dot NET, I wish to run a timer and read the entire input
buffer as a string. I found some sample code and interpreted it like this:

  Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick

        Dim j As Integer
        Dim i As Integer

        Dim strDataIn As String
        Dim DataIn As Array

        Try
            j = 0
            While switchcom.Read(1) <> -1
                DataIn(j) = Asc(switchcom.InputStreamString.Chars(0))
                j += 1

                strDataIn = ""
                For i = 0 To DataIn.Length - 1
                    strDataIn &= DataIn(i)
                Next

            End While

        Catch
            ' // "Switcher buffer empty"
        End Try

        TextBox1.Text = strDataIn

    End Sub


But I can't get anything in the port. Furthermore, when option strict is on,
the compiler complains about "late binding" on DataIn(j). I'm still pretty
new to this stuff: Should I just turn Option Strict off, or do I need to fix
something?

Any help appreciated, thanks.

--
Dave Harry

Author
23 Mar 2006 8:55 AM
Pieter
the .NET Framework contains (again) a serial-port component... much easier
to use :-)

Show quoteHide quote
"Dave Harry" <DaveHa***@please.keep.replies.in.the.newsgroup> wrote in
message news:e9NFRtjTGHA.1868@TK2MSFTNGP09.phx.gbl...
>I found the RS232 class from MS's 101 VB samples.
>
> Writing to the port works fine. (I've got hyperterminal on the other comm
> port and a crossover cable between COM1 and COM2)
> The port is opened with:
>
>    Public switchcom As New Rs232
>    switchcom.Open(2, 57600, 8, Rs232.DataParity.Parity_None,
> Rs232.DataStopBit.StopBit_1, 512)
>
>
> But reading is giving me no end of trouble. Since there are no com port
> events anymore in dot NET, I wish to run a timer and read the entire input
> buffer as a string. I found some sample code and interpreted it like this:
>
>  Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Timer1.Tick
>
>        Dim j As Integer
>        Dim i As Integer
>
>        Dim strDataIn As String
>        Dim DataIn As Array
>
>        Try
>            j = 0
>            While switchcom.Read(1) <> -1
>                DataIn(j) = Asc(switchcom.InputStreamString.Chars(0))
>                j += 1
>
>                strDataIn = ""
>                For i = 0 To DataIn.Length - 1
>                    strDataIn &= DataIn(i)
>                Next
>
>            End While
>
>        Catch
>            ' // "Switcher buffer empty"
>        End Try
>
>        TextBox1.Text = strDataIn
>
>    End Sub
>
>
> But I can't get anything in the port. Furthermore, when option strict is
> on, the compiler complains about "late binding" on DataIn(j). I'm still
> pretty new to this stuff: Should I just turn Option Strict off, or do I
> need to fix something?
>
> Any help appreciated, thanks.
>
> --
> Dave Harry
>
Author
23 Mar 2006 4:24 PM
Dick Grier
Hi,

Visual Studio 2005 has the System.IO.Ports namespace.  Earlier versions did
not.  I presume, because of the question, that OP is using VS2003.

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004.
See www.hardandsoftware.net for details and contact information.
Author
23 Mar 2006 4:23 PM
Dick Grier
Hi,

>>
But reading is giving me no end of trouble. Since there are no com port
events anymore in dot NET, I wish to run a timer and read the entire input
buffer as a string. I found some sample code and interpreted it like this:
<<

Depends on the class/object that you are using.  If you download
DesktopSerialIO.dll from my homepage, you will see them (and the use is
straight forward).

Dick

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004.
See www.hardandsoftware.net for details and contact information.
Author
27 Mar 2006 12:16 AM
Dave Harry
Thank you Dick
That seems to be just what I want.

The finer points of using it are coming to me slowly, but it seems to have
most everything.

--
Dave Harry

Show quoteHide quote
"Dick Grier" <dick_grierNOSPAM@.msn.com> wrote in message
news:upz7ZYpTGHA.4772@TK2MSFTNGP09.phx.gbl...
> Hi,
>
>>>
> But reading is giving me no end of trouble. Since there are no com port
> events anymore in dot NET, I wish to run a timer and read the entire input
> buffer as a string. I found some sample code and interpreted it like this:
> <<
>
> Depends on the class/object that you are using.  If you download
> DesktopSerialIO.dll from my homepage, you will see them (and the use is
> straight forward).
>
> Dick
>
> --
> Richard Grier, MVP
> Hard & Software
> Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
> Edition,
> ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004.
> See www.hardandsoftware.net for details and contact information.
>