473,769 Members | 2,143 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

serialport read buffer

Hello,

I added a serial-USB converter to my laptop, it appear as USB serial
port COM4, and I wrote an application to read 78k data from this port.
In my VC++ express code, I defined ReadBufferSize = 78k, and
ReceivedBytesTh reashold = 78k so that I can get the whole data with
one ReadExisting() method when DataReceived event fires.

However, everytime the readbuffer only received 4096 bytes, but when I
test the same code with real serial port COM1, it received full 78k
data. There is no buffer configuration in driver of USB converter, and
it's impossible the converter has 4k limitation, this is confirmed
when I use hypertermial to capture the data, I got full 78k data too.

There must be something I don't know in .net or serialport class. Can
anyone tell me where I am wrong?

Thanks a lot!

Apr 22 '07 #1
4 4620

<ch******@yahoo .comwrote in message
news:11******** *************@l 77g2000hsb.goog legroups.com...
Hello,

I added a serial-USB converter to my laptop, it appear as USB serial
port COM4, and I wrote an application to read 78k data from this port.
In my VC++ express code, I defined ReadBufferSize = 78k, and
ReceivedBytesTh reashold = 78k so that I can get the whole data with
one ReadExisting() method when DataReceived event fires.

However, everytime the readbuffer only received 4096 bytes, but when I
test the same code with real serial port COM1, it received full 78k
data. There is no buffer configuration in driver of USB converter, and
it's impossible the converter has 4k limitation, this is confirmed
when I use hypertermial to capture the data, I got full 78k data too.
How does this prove the converter has no 4k limitation? Hyperterminal will
immediately call ReadFile again each time any data is received, until of
course the whole block is eventually received.

Have you used sysinternals (now part of Microsoft TechNet) portmon to
discover the actual call sequence?
>
There must be something I don't know in .net or serialport class. Can
anyone tell me where I am wrong?
I suspect BeginRead/EndRead would "work" more often. What happens is that
as soon as the PC becomes aware that data is received (one USB frame worth),
the DataReceived event fires. But you should always handle partial reads,
and issue a new read for the remaining data.
>
Thanks a lot!

May 3 '07 #2
I use these converters all the time, and as Ben surmised, the drivers (for
the ones I use, at least) are limited to 4096 bytes at a time. You'll have to
make multiple calls to read all 78 K.

"ch******@yahoo .com" wrote:
Hello,

I added a serial-USB converter to my laptop, it appear as USB serial
port COM4, and I wrote an application to read 78k data from this port.
In my VC++ express code, I defined ReadBufferSize = 78k, and
ReceivedBytesTh reashold = 78k so that I can get the whole data with
one ReadExisting() method when DataReceived event fires.

However, everytime the readbuffer only received 4096 bytes, but when I
test the same code with real serial port COM1, it received full 78k
data. There is no buffer configuration in driver of USB converter, and
it's impossible the converter has 4k limitation, this is confirmed
when I use hypertermial to capture the data, I got full 78k data too.

There must be something I don't know in .net or serialport class. Can
anyone tell me where I am wrong?

Thanks a lot!

May 4 '07 #3
I was looking for confirmation of this 4096 byte limitation I'm having using
writefile on an open serial port connected to a bluetooth dongle and I saw
these posts .
Unfortunately turning the single write into multiple 4k writes introduces
some performance problems on the device I'm communicating with - there is a
big hit getting the i/o going . My tests show this isn't much of an issue if
the other device is a PC but not so with my bluetooth dip module . Sigh.
Also I will make note of the fact that you don't get an error , just a
reduced number of bytes written to signal you to the fact the behavior is
different than native serial port I/O .
Sigh.
"ch******@yahoo .com" wrote:
Hello,

I added a serial-USB converter to my laptop, it appear as USB serial
port COM4, and I wrote an application to read 78k data from this port.
In my VC++ express code, I defined ReadBufferSize = 78k, and
ReceivedBytesTh reashold = 78k so that I can get the whole data with
one ReadExisting() method when DataReceived event fires.

However, everytime the readbuffer only received 4096 bytes, but when I
test the same code with real serial port COM1, it received full 78k
data. There is no buffer configuration in driver of USB converter, and
it's impossible the converter has 4k limitation, this is confirmed
when I use hypertermial to capture the data, I got full 78k data too.

There must be something I don't know in .net or serialport class. Can
anyone tell me where I am wrong?

Thanks a lot!

Jun 2 '07 #4

"chaz" <ch**@newsgroup .nospamwrote in message
news:DF******** *************** ***********@mic rosoft.com...
>I was looking for confirmation of this 4096 byte limitation I'm having
using
writefile on an open serial port connected to a bluetooth dongle and I saw
these posts .
Unfortunately turning the single write into multiple 4k writes introduces
some performance problems on the device I'm communicating with - there is
a
big hit getting the i/o going . My tests show this isn't much of an issue
if
the other device is a PC but not so with my bluetooth dip module . Sigh.
I would suggest getting a USB bluetooth dongle and take out the serial
conversion entirely. The maximum rate of bluetooth is much higher than
async serial typically reaches.
Also I will make note of the fact that you don't get an error , just a
reduced number of bytes written to signal you to the fact the behavior is
different than native serial port I/O .
That's true, and while it's more common dealing with sockets, any time you
do I/O you should be prepared that only part of your data was accepted and
you need to call again with the rest.
Sigh.
"ch******@yahoo .com" wrote:
>Hello,

I added a serial-USB converter to my laptop, it appear as USB serial
port COM4, and I wrote an application to read 78k data from this port.
In my VC++ express code, I defined ReadBufferSize = 78k, and
ReceivedBytesT hreashold = 78k so that I can get the whole data with
one ReadExisting() method when DataReceived event fires.

However, everytime the readbuffer only received 4096 bytes, but when I
test the same code with real serial port COM1, it received full 78k
data. There is no buffer configuration in driver of USB converter, and
it's impossible the converter has 4k limitation, this is confirmed
when I use hypertermial to capture the data, I got full 78k data too.

There must be something I don't know in .net or serialport class. Can
anyone tell me where I am wrong?

Thanks a lot!


Jun 6 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
17024
by: DraguVaso | last post by:
Hi, I'm experimenting with the Serial Port in VB.NET 2005. Although it isn't that easy to get any feedback from my COM-port as I thought it would be... How can I read all the Data that the port sends back? I tryed with SerialPort1.ReadLine, but that blocks the application and takes a lot of time (10 seconds!), I tryed SerialPort1.Read, but I have to read it into a buffer and has to indicate the count, but how do I know this?
2
10527
by: Jan | last post by:
Hello there, I've got a strange problem using the readline method in vb2005 for reading the serial port. If I use the readchar method I can receive one character from serialport. This is the code I use: Function ReceiveSerialData() As String ' Receive strings from a serial port. Dim returnStr As String = ""
4
29287
by: Ben Kim | last post by:
Hello all, Does anyone have an example on how to implement the new SerialPort Class in VB.NET? I have been able to create the class, send (.WriteLine) to the port and Read from the port but cannot figure out how to use the Events to tell my program that data is available in the serial port buffer. I have searched the internet and MSDN and there doesn't appear to be any full example on how to do this simple task.
2
2564
by: DJohnson | last post by:
Hello everyone, Please forgive me for my ignorance or lack of understanding on the following technology, as I am by no means an expert in serial IO. I am writing an application that communicates to a custom hardware device that requires a 4 byte message to be sent every 500ms to keep it alive. I have used VB6 to create a prototype application that works fine (using the MSComm activex control) to send the 4 bytes of data at a 500ms...
4
8663
by: =?Utf-8?B?S3Jpc3RvZmZlciBQZXJzc29u?= | last post by:
Does anyone know if it's possible to get the Win32 handle to the serial port used under the hood in System.IO.SerialPort? The reason I want it is so I'd be able to make changes the DCB struct. I want to set the fRtsControl to RTS_CONTROL_TOGGLE so the RTS signal will be reset automatically when the TX buffer is empty. - Kristoffer -
0
2149
by: grappeggia | last post by:
Hi everybody, I`m doing a project in which a microcontroller realises an A/D conversion of 8 channels and send then to the computer using the USB, over one serialport interface. On the PC, I`m using a VB software that receives and store the data from the microcontroller. On this program, the user enters with the sampling time and the name of the storage file. So, to start the pickup, the user must click on the "Coletar" button. Then the...
1
1832
by: =?Utf-8?B?Q2hyaXN0aWFuIEhhdmVs?= | last post by:
Hi, I communicate with a device using the .NET 2.0 serial port class. I am notified when some data are received by the event. If I read the buffer there is still the "old" data + the new data. Why is the buffer not cleaned? When the buffer will be cleaned? Christian
1
1897
by: Pubs | last post by:
Hi, I am using the serial and I have a problem with the timeout. I am defining my array to fixed length and call the read function. I assumed that the function will not return data until it reads the number of bytes I requested. My timeout is very large so it will not timeout. However I noticed that it does return values even before it gets all the data I requested. I have included some code lines below. ReadBuffer = new byte;
8
6477
by: Kevin.M.Jonas | last post by:
I have the following method that handles the data received event: private void _port_DataReceived(object sender, SerialDataReceivedEventArgs e) { string data = _port.ReadExisting(); _log.LogToFile(data, true); } The LogToFile function logs data to a file. The second parameter indicate if the file should timestamp the message.
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10210
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10039
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9860
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7406
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5445
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3955
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
2
3560
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2814
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.