Solved

VC4.0 Multithreaded comm port I/O

Posted on 1997-03-03
3
367 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 100 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

821 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