Solved

VC4.0 Multithreaded comm port I/O

Posted on 1997-03-03
3
373 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

623 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