473,569 Members | 2,756 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using the RS232.vb component for serial port control

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
6 9119
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
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******** ******@tk2msftn gp13.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
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
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********@asc entmedianospam. com> wrote in message
news:ut******** *****@TK2MSFTNG P12.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
I use that same RS232.vb code. Mine works like this:

Try
j = 0
While SwitchCOM.Read( 1) <> -1
DataIn(j) =
Asc(SwitchCOM.I nputStreamStrin g.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
I use that same RS232.vb code. Mine works like this:

Try
j = 0
While SwitchCOM.Read( 1) <> -1
DataIn(j) =
Asc(SwitchCOM.I nputStreamStrin g.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2868
by: bryja_klaudiusz[at]poczta[dot]fm | last post by:
Hi, I need free for comercial use serial communiaction component for CSharp. Where can I get library? -- *Best regards,* Klaudiusz Bryja
4
11174
by: joe bloggs | last post by:
I am writing a mobile application to interface with a legacy system and I am planning to use web services to communicate with this system. The legacy system receives data through a serial port. What I would like to do is make the serial port accessible via a web service. The web service and the legacy application would be running on the...
2
5123
by: Wouter van Teijlingen | last post by:
Dear Readers, I was reading about how to control the COM and LPT port using VB .NET. I've found a lot of information, and it was very useful to me. I found an example program on the site of Microsoft. You can find it overhere: http://www.microsoft.com/downloads/details.aspx?FamilyID=075318ca-e4f1-4846-912c-b4ed37a1578b&DisplayLang=en I...
13
6840
by: jay.dow | last post by:
I want to write to the pins of an RS232 without using the serial protocol. The use would be every pin could act to complete a circuit in customized hardware. I could use python to communicate serially to a BASIC stamp or a Javelin stamp and then use the stamp to set however many pins as 0's or 1's but should it be that hard to do with...
4
1631
by: Q | last post by:
Hello you all, any of you know of a good and easy to use component to access the serial port? Regards, Q
4
5496
by: Dave Harry | last post by:
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)
0
4481
by: nmsreddi | last post by:
Hi friends I am working on c#.net . i am developing a windows application using c# 2003 aim of my application is sending and receiving sms using GSM modem. for this i am using AxMscomm control which is there in VB6.0(telephone device) by using this i am able to receive the data and able to send message .but the
2
5485
by: egress | last post by:
Forgive me for stupid questions for I am new to serial IO programming. I am developing an app that will need to communicate with a device via RS232 protocol using a standard 9 pin serial cable. From what I understand this can be accomplished relativly easy using .net 2.0 SerialPort component over a COM port. My question: because most...
2
4376
by: eljainc | last post by:
Hello, Does anybody know if there are any freeware or inexpensive RS232/ Serial port libraries that are C# .NET 1.1 or .NET 2.0? I think there is a SerialPort class in .NET 2.0 /C# but it is probably not too robust. Thanks Mike
0
7697
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8120
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7672
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7968
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5512
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1212
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.