Non Overlapped Serial Ports

Posted on 2004-11-25
Last Modified: 2013-12-03
I am using Embbeded Visual C++ 4.0 to write an application on Pocket PC 2003 platform to communicate with another device via bluetooth serial port profile. I undestand that serial ports on PPC are Non Overlapped. I have to create a thread to read data and a thread to send the data. My problem is that my application can only send data once and then hangs. How do I synchronise the write thread and the receiving thread. is there any difference in using AfxBeginThread and CreateThread functions ? I also need to read all the data when it arrives in  the receive buffer instead of reading it character by character and specificing the receive buffer size limit. How do I implement an event handler to do this ? I have not put any of my code because I have decided to start all over again. Could someone please help it's quite urgent.

Question by:Code_Angel
    LVL 13

    Expert Comment

    I would suggest to have only one thread which does all the communication with the serial port. The advantage of 2 threads for sending will be removed by the need of synchronising access to the serial port. My idea is to use an UI thread:
    and do the reading in the OnIdle of the CWinThread class and writing is done in a message handler.
    LVL 13

    Accepted Solution

    LVL 86

    Assisted Solution

    >> How do I synchronise the write thread and the receiving thread

    You'd use a CRITICAL_SECTION to protect the data and e.g. an Event to signal 'data ready'

    >>is there any difference in using AfxBeginThread and CreateThread functions ?

    The 1st one is MFC-only and can handle CWinThread objects, that's the main difference.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
    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.…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…

    728 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

    16 Experts available now in Live!

    Get 1:1 Help Now