Com ports

?

}{

I have an app that reads a character string on com 1, waits for a signal
(any ascii char) on com 2, then outputs the string on com 2.

I seem to have a problem with the timing. It just so happens that the signal
from com2 arrives at the same time as the next string for com1.

Do the com ports run in sepaerate threads by default, or should I be doing
something in code to make this happen.

Thanks.
 
C

christery

Do the com ports run in sepaerate threads by default, or should I be doing
something in code to make this happen.

I think you should handle the race condition, a mutex solution would
help, there is buffers to use so you wont lose data eaven if waiting
in one receive event until that is finished. but that is a rather bad
way to solve the problem, if a telex isn't read all the way the
process will be hanging there.
UARTS (like 16550) have a small buffer (16 bytes, I think) but issue
an interrupt and will be handeld by the driver, the buffer size is
normally set to larger than the maximum expected packet in your
program language of choice.

//CY
 
G

Gilles Kohl [MVP]

I have an app that reads a character string on com 1, waits for a signal
(any ascii char) on com 2, then outputs the string on com 2.

I seem to have a problem with the timing. It just so happens that the signal
from com2 arrives at the same time as the next string for com1.

Do the com ports run in sepaerate threads by default, or should I be doing
something in code to make this happen.

How are you handling the incoming data, via polling, or by handling
the DataReceived event? I'd recommend the latter. Have a
SerialDataReceivedEventHandler method for COM1, and another one for
COM2. The first one just buffers received data into a public string,
the second one sends the buffered string to COM2 on reception of the
trigger character, and empties the buffer. (Synchronize on the buffer)

I'm not quite sure how your app should handle characters incoming on
COM2 with no buffered string present from COM1, or indeed multiple
incoming strings on COM1 with not COM2 request in between - you'll
need to decide what to do here. If memory serves, the incoming serial
data received calls are not on the UI thread, not sure though.

Regards,
Gilles.
 

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