Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VC4.0 Multithreaded comm port I/O

Posted on 1997-03-03
3
Medium Priority
?
393 Views
Last Modified: 2013-12-03
I am writing a Visual C++ 4.0 app that requires the use of comm port I/O.  Basically, the app has three threads; one (thread 1) that sits and watches the comm port for incoming data and immediately puts it in a buffer, one (thread 2) that processes the data that came in from thread 1, and one (thread 3) that generates data and writes it to the comm port.

The problem is, if I disable thread 3, so that it is not writing any data to the comm port, it is able to run fine.  However, once I enable thread 3, so that it is both writing to the comm port and reading from the comm port, I have some times where some bytes are missing from the incoming data stream.  (I verified this by inspecting the data at the remote end before it got transmitted).  Not that they are corrupted, just flat out missing, and this is over a null modem cable.

I am using WriteFile and ReadFile (overlapped IO) to interface with the comm ports.  Since I check the data right before it goes in and right after it comes out, I start to feel the need to check what's going on at a deeper level inside the OS.

Any advice would be appreciated.
0
Comment
Question by:luttrell
3 Comments
 

Expert Comment

by:isak
ID: 1300035
I don't know the reason of your problem, but you may try to put a mutex on the Read and Write operations, so that there will be no simultaneous Read and Write. maybe it will help...
0
 

Expert Comment

by:MikeDabbs
ID: 1300036
Have you verified that what you write is ACTUALLY what Windows said you wrote?  i.e. the return value of the number of bytes written on the sending side?  If I remember correctly, Windows can write a short block when it reaches the capacity of its internal buffers and times out.
0
 
LVL 1

Accepted Solution

by:
glittle earned 300 total points
ID: 1300037
Are you using any kind of handshaking or flow control?  It is very possible that your missing characters problem is because of overflow in the com port.  

Try using RTS/CTS or XON/XOFF and turn on the FIFO if it is 16550.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question