472,144 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,144 software developers and data experts.

Simple serial port

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
Nov 16 '05 #1
1 4796
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

"ORC" <or*@sol.dk> wrote in message
news:eP**************@TK2MSFTNGP11.phx.gbl...
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

Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by ^CeFoS^ | last post: by
38 posts views Thread by jrlen balane | last post: by
2 posts views Thread by willie | last post: by
3 posts views Thread by collinm | last post: by
13 posts views Thread by Al the programmer | last post: by
13 posts views Thread by Rob | last post: by
3 posts views Thread by naveen.sabapathy | last post: by
reply views Thread by Saiars | last post: by
reply views Thread by leo001 | last post: by

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.