Simple serial port

O

ORC

Hi,

I'm looking for a way to implement a simple functionality in my serial port
C# wrapper. I'm making a program that must run on both a Pocket PC and a
"normal" PC. The application is quite simple:
A calling thread is blocked untill Readfile returns with "bytesToRead"
numbers of bytes or untill "TotalTimeout" specified in the "COMMTIMEOUT"
struct has been exceeded. Another thread must be able to write to the same
serial port while the first thread is waiting in the readfile function. This
all works very well on the Pocket PC! But on the desktop PC the writefile is
prevented to be executed until the readfile has finished. I have tried
setting the Overlapped to true in createfile and applied both readfile and
writefile with an overlapped struct - This makes however the readfile return
immediately no matter if any characters are received and whatever is
specified in the COMMTIMEOUT structure. The COMMTIMEOUT struct is specified
as this:
CommPort.ReadIntervalTimeout = 5000;
CommPort.ReadTotalTimeoutMultiplier = 0;
CommPort.ReadTotalTimeoutConstant = 5000;
CommPort.WriteTotalTimeoutMultiplier = 0;
CommPort.WriteTotalTimeoutConstant = 1000;

Does anyone knows a proper way to handle this??? Any help is highly
appreciated!

I don't use WaitCommEvents and all that stuff and would prefer not to (it
shouldn't be neccesary as the application is quite simple). I have had a
look at the Serial Class from OpenNetCF but it is far to heavy for my
application.

Thanks
Ole
 
J

Jim H

I do that in my app and it works fine. I write in one thread while reading
from another. I can't be sure that the write is not being blocked by the
read since my read thread can be very busy, but I have not coded it to be
exclusive, nor have I seen any issues leading me to think it is.

You probably already know this but the commtimeouts only work if you receive
at least one byte from the read. The timeout is a count between read bytes
and does not start until the first byte arrives. Otherwise it blocks
forever.

jim
 

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