By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,333 Members | 1,047 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,333 IT Pros & Developers. It's quick & easy.

Help needed using sample RS232 class to read from serial port

P: n/a
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
Mar 23 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
the .NET Framework contains (again) a serial-port component... much easier
to use :-)

"Dave Harry" <Da*******@please.keep.replies.in.the.newsgroup> wrote in
message news:e9**************@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

Mar 23 '06 #2

P: n/a
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.
Mar 23 '06 #3

P: n/a
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.
Mar 23 '06 #4

P: n/a
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

"Dick Grier" <dick_grierNOSPAM@.msn.com> wrote in message
news:up**************@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.

Mar 27 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.