Solved

VC4.0 Multithreaded comm port I/O

Posted on 1997-03-03
3
363 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

763 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

9 Experts available now in Live!

Get 1:1 Help Now