asynchronous serial i/o

M

Martijn

Hi,

I am trying to perform asynchronous serial (RS232 port) I/O in C# in a
"proper" manner. I noticed there is an event that will tell me when there
is something on the port, but I can't find a similar construct for writing
to the port.

Although the documenation states that SerialPort.Write() and
SerialPort.WriteLine() write to the buffer, they do not return until all
bytes have been actually transmitted (I tested this by sending 1K @
1200bps). I was hoping for some way to send something to the driver, and be
notified when it was transmitted on the port. Something like what would
happen by specifying FILE_FLAG_OVERLAPPED to the native Win32 CreateFile()
call.

My options:

1) Create my own thread(s) to do the asynchronous reading and writing (seems
a bit expensive)
2) Use P/Invoke on CreateFile and whatever I need to write to it (not really
something I prefer)
3) I have missed something, and there is a "better way"

Any pointers would be greatly appreciated!

Thanks for the help,
 
J

Jeroen Mostert

Martijn said:
I am trying to perform asynchronous serial (RS232 port) I/O in C# in a
"proper" manner. I noticed there is an event that will tell me when there
is something on the port, but I can't find a similar construct for writing
to the port.
Tried SerialPort.BaseStream.BeginRead/Write yet?
 
M

Martijn

Jeroen said:
Tried SerialPort.BaseStream.BeginRead/Write yet?

Hi Jeroen,

Thanks for pointing this out, exactly what I was looking for. I knew
SerialPort used some kind of stream, and when browsing the documentation I
overlooked that property and it being so obvious to get at :S

Thanks a million,
 

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