Asynchronous Serial port

  • Thread starter shayke via DotNetMonster.com
  • Start date
S

shayke via DotNetMonster.com

Hello,

I am trying to write asynchronous serial port.
meaning, read and write operations are made via async cllbacks.
so far so good.
I open my port in continues state:
1)Set the BytesToRead property of the serial port.
2)open the port
3)generate read request
4)meanwhile generate write request.
5)in result, the read operation is executed(provided that the BytesToRead are
present n the stream)
i encountered a problem that despite of Setting the BytesToRead property,the
read operation is executed and reads 1 byte from the stream.
after the read operation is completed i generate another async read request
so the port is always in "Listening" mode.

am i doing something wrong?
can't i work asynchronically?
do i have to lock the stream or the port or the buffer itself?

Thanks
 
S

shmulik via DotNetMonster.com

shayke said:
Hello,

I am trying to write asynchronous serial port.
meaning, read and write operations are made via async cllbacks.
so far so good.
I open my port in continues state:
1)Set the BytesToRead property of the serial port.
2)open the port
3)generate read request
4)meanwhile generate write request.
5)in result, the read operation is executed(provided that the BytesToRead are
present n the stream)
i encountered a problem that despite of Setting the BytesToRead property,the
read operation is executed and reads 1 byte from the stream.
after the read operation is completed i generate another async read request
so the port is always in "Listening" mode.

am i doing something wrong?
can't i work asynchronically?
do i have to lock the stream or the port or the buffer itself?

Thanks


I encountered the same problem.at the first read operation the read operation
returns after reading only the first byte.i think it is a problem of timeout
settings.i am not sure.
anyone else knows???
 
H

Helge Jensen

shayke said:
am i doing something wrong?
can't i work asynchronically?
do i have to lock the stream or the port or the buffer itself?

In general, all .NET read primitives can read less bytes than "requested".

If bytes are not arriving fast the async read operation *should* return
a number of bytes less than BytesToRead.

If you need to wait until a certain number of bytes have arrived you
must copy those bytes into a buffer yourself and signal an event when
it's full.
 

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