Solved

VC4.0 Multithreaded comm port I/O

Posted on 1997-03-03
3
365 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get the most recent file to copy into a sql table with ssis 2 95
Windows Drag & Drop Location 2 94
MSDN Subscription - Azure and NFP's 3 64
Windows Process running 3 47
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
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…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now