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

Using the RS232.vb component for serial port control

P: n/a
I am using the RS232.vb class to talk to the serial port. The problem I am
having is when I try to read if anything is on the comm port. I call the
read method, with the number of bytes I am expecting to read. As long as I
know the length of the command that I will be getting on the input of the
port it works great.

The problem is when I don't know how long the data I am receiving is. If I
request more bytes than I know I am getting back (ie. I would request to
read the entire buffer, and then just see what is in that buffer) the class
throws a timeout error. I'm assuming that it is waiting for of the bytes
that I specified.

With the VB6 Comm control I was able to read the input and if there was
nothing there it would just return a blank string.

Is there any way to tell how many bytes are in the buffer before I try to
read it, or some way to read the port when there is nothing there and not
get an error?

Thanks,
Ken Breit


Nov 20 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Cor
Hi Bred,

In this resource kit is a sample of using Com ports

Maybe you can use it.

http://msdn.microsoft.com/vbasic/vbrkit/default.aspx

And if you have problems installing it

http://msdn.microsoft.com/vbasic/vbr...q/#installvdir

I hope this helps a little bit?

Cor

I am using the RS232.vb class to talk to the serial port. The problem I am having is when I try to read if anything is on the comm port. I call the
read method, with the number of bytes I am expecting to read. As long as I know the length of the command that I will be getting on the input of the
port it works great.

The problem is when I don't know how long the data I am receiving is. If I request more bytes than I know I am getting back (ie. I would request to
read the entire buffer, and then just see what is in that buffer) the class throws a timeout error. I'm assuming that it is waiting for of the bytes
that I specified.

With the VB6 Comm control I was able to read the input and if there was
nothing there it would just return a blank string.

Is there any way to tell how many bytes are in the buffer before I try to
read it, or some way to read the port when there is nothing there and not
get an error?

Nov 20 '05 #2

P: n/a
Thanks Cor. Yes I've looked at some of these controls, but have not tried
them out yet. I liked the idea of the rs232 class and wanted to use it. I
most likely will use one of those components, but I just wanted to see if
there was a way.

Thanks,
Ken
"Cor" <no*@non.com> wrote in message
news:Oz**************@tk2msftngp13.phx.gbl...
Hi Bred,

In this resource kit is a sample of using Com ports

Maybe you can use it.

http://msdn.microsoft.com/vbasic/vbrkit/default.aspx

And if you have problems installing it

http://msdn.microsoft.com/vbasic/vbr...q/#installvdir

I hope this helps a little bit?

Cor

I am using the RS232.vb class to talk to the serial port. The problem I am
having is when I try to read if anything is on the comm port. I call the read method, with the number of bytes I am expecting to read. As long as I
know the length of the command that I will be getting on the input of
the port it works great.

The problem is when I don't know how long the data I am receiving is. If I
request more bytes than I know I am getting back (ie. I would request to
read the entire buffer, and then just see what is in that buffer) the

class
throws a timeout error. I'm assuming that it is waiting for of the

bytes that I specified.

With the VB6 Comm control I was able to read the input and if there was
nothing there it would just return a blank string.

Is there any way to tell how many bytes are in the buffer before I try to read it, or some way to read the port when there is nothing there and not get an error?


Nov 20 '05 #3

P: n/a
Hi,

That class is a little simplistic, IMO. Naturally, since it is provided as
source code, you can modify it as needed. I have another one in my book (see
below) -- I prefer its implementation, and it doesn't have the limitation
that you mention, and there are a number of alternates available online.
You also can download NETComm.ocx from my homepage, for an ActiveX solution.

Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
Edition ISBN 1-890422-27-4 (391 pages) published February 2002.
Nov 20 '05 #4

P: n/a
Hi Ken

Have you tried the class at

http://www.codeworks.it/net/VBNetRs232.htm

I have found it to be particularly thorough.

HTH

Charles
"Ken Breit" <kd********@ascentmedianospam.com> wrote in message
news:ut*************@TK2MSFTNGP12.phx.gbl...
I am using the RS232.vb class to talk to the serial port. The problem I am having is when I try to read if anything is on the comm port. I call the
read method, with the number of bytes I am expecting to read. As long as I know the length of the command that I will be getting on the input of the
port it works great.

The problem is when I don't know how long the data I am receiving is. If I request more bytes than I know I am getting back (ie. I would request to
read the entire buffer, and then just see what is in that buffer) the class throws a timeout error. I'm assuming that it is waiting for of the bytes
that I specified.

With the VB6 Comm control I was able to read the input and if there was
nothing there it would just return a blank string.

Is there any way to tell how many bytes are in the buffer before I try to
read it, or some way to read the port when there is nothing there and not
get an error?

Thanks,
Ken Breit

Nov 20 '05 #5

P: n/a
I use that same RS232.vb code. Mine works like this:

Try
j = 0
While SwitchCOM.Read(1) <> -1
DataIn(j) =
Asc(SwitchCOM.InputStreamString.Chars(0))
j += 1
End While
Catch
' // "Switcher buffer empty"
End Try

This fills the array DataIn() with your characters. If you want all
your characters to be in a string, do something like:

dim strDataIn as string = ""
for i = 0 to DataIn.Length - 1
strDataIn &= DataIn(i)
next

Good stuff! :)

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 20 '05 #6

P: n/a
I use that same RS232.vb code. Mine works like this:

Try
j = 0
While SwitchCOM.Read(1) <> -1
DataIn(j) =
Asc(SwitchCOM.InputStreamString.Chars(0))
j += 1
End While
Catch
' // "Switcher buffer empty"
End Try

This fills the array DataIn() with your characters. If you want all
your characters to be in a string, do something like:

dim strDataIn as string = ""
for i = 0 to DataIn.Length - 1
strDataIn &= DataIn(i)
next

Good stuff! :)

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.