DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    George Kulz Guest

    Serial port problems.


    Hi all.

    I have a program set up that simply monitors the serial port, with no timeout.
    Every time it receives 7 bytes in succession, it parses the "message" received
    and displays the data in appropriate fields on the screen. I have a class
    called CSerialIO which is derived from the CFile class. A function called
    OpenCOM sets up communication on the port and then kicks off a thread which
    sits in a read loop. Everything runs fine until I go to close the dialog
    box. When attempting to close the communication, however, the application
    hangs because the read thread is sitting at the Read command waiting for
    input from the serial port. It is unable to process any thread messages
    while it is sitting there, so it cannot shut itself down. Does anyone know
    how I might be able to force the thread to process messages? Or somehow
    force a return from the Read command? Any help would be appreciated.

    -George Kulz, Senior Software Engineer
    PowerSmart Inc.

    ----------------------

    The views expressed here are mine and do not reflect the official position
    of my employer, or the organization through which the Internet was accessed.


  2. #2
    Patrick Toohey Guest

    Re: Serial port problems.


    George,

    The thread can be terminated in four different ways. The best method is for
    the thread to return on its own. This ensures all objects within the thread
    have called their destructors, as well as other OS cleanup. If this is not
    possible, the thread can kill itself with the ExitThread function or another
    thread can kill it with the TerminateThread function. Finally if the process
    containing the thread terminates, the thread itself will also be terminated.
    This sounds like your case, so I don't see why the thread is not terminated
    unwillingly. If you are terminating the application all together, windows
    will perform any clean up for you, so killing the thread is the quick and
    dirty way to exit.

    "George Kulz" <gkulz@powersmart.com> wrote:
    >
    >Hi all.
    >
    >I have a program set up that simply monitors the serial port, with no timeout.
    > Every time it receives 7 bytes in succession, it parses the "message" received
    >and displays the data in appropriate fields on the screen. I have a class
    >called CSerialIO which is derived from the CFile class. A function called
    >OpenCOM sets up communication on the port and then kicks off a thread which
    >sits in a read loop. Everything runs fine until I go to close the dialog
    >box. When attempting to close the communication, however, the application
    >hangs because the read thread is sitting at the Read command waiting for
    >input from the serial port. It is unable to process any thread messages
    >while it is sitting there, so it cannot shut itself down. Does anyone know
    >how I might be able to force the thread to process messages? Or somehow
    >force a return from the Read command? Any help would be appreciated.
    >
    >-George Kulz, Senior Software Engineer
    > PowerSmart Inc.
    >
    >----------------------
    >
    >The views expressed here are mine and do not reflect the official position
    >of my employer, or the organization through which the Internet was accessed.
    >



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links