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

serialport read buffer

P: n/a
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
ReceivedBytesThreashold = 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
Share this Question
Share on Google+
4 Replies


P: n/a

<ch******@yahoo.comwrote in message
news:11*********************@l77g2000hsb.googlegro ups.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
ReceivedBytesThreashold = 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

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

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

P: n/a

"chaz" <ch**@newsgroup.nospamwrote in message
news:DF**********************************@microsof t.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
ReceivedBytesThreashold = 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 discussion thread is closed

Replies have been disabled for this discussion.