Help needed using sample RS232 class to read from serial port

D

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.
 
D

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.
 
D

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.
 
D

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top