Re: strange problem with serial communication

From: Maverick (Maverick_at_maverick.com)
Date: 12/27/04


Date: Mon, 27 Dec 2004 11:17:08 +0800

Solved! Thanks! Though I don't quite understand the part of your post about
thread, I'll try to learn more about it.
"Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp> ????
news:OKoo80c6EHA.3820@TK2MSFTNGP11.phx.gbl...
> Maverick wrote:
>
> > Hi, all
> >
> > I met a big trouble. I am using MFC and multi-thread to write a serial
port
> > communication program. Each time I send a string, I alwayse get part of
it.
> > For example , I send a string of 120 characters, what I receive is a
string
> > which contains only top 8 or 16 or 24 or 32 characters. I cannot receive
the
> > same string at all. I've tried different baud rate, including
19200,9600,
> > but all failed. Below is part of my code.
>
> Your code is written to stop reading whenever ReadFile gets a timeout,
> but you have set the timeout to zero. The code is also written to input
> only one byte for each ReadFile call. These are unreliable things to do.
>
> Pass a buffer to ReadFile that is large enough to receive the maximum
> expected number of characters. And set the timeout to be a generous
> amount of time that you are sure indicates all incoming characters have
> stopped.
>
> There are also unreliable features in your thread design. In MFC, the
> thread should be started with AfxBeginThread and it should not access
> the dialog controls. This can cause program lockup. It is also not
> clear how you expect the main thread to know when the reading is
> complete. No interthread signaling or synchronization is present in
> your code, so it may be that your main thread is accessing the buffer
> before the reading is complete.
>
> --
> Scott McPhillips [VC++ MVP]
>



Relevant Pages

  • Re: strange problem with serial communication
    ... Each time I send a string, ... > Your code is written to stop reading whenever ReadFile gets a timeout, ... > but you have set the timeout to zero. ... > only one byte for each ReadFile call. ...
    (microsoft.public.vc.mfc)
  • Re: Learning the fretboard..
    ... Sight reading at a higher level entails recognition of musical ... is your default handling of two whole steps along a string, ... -Start with a major triad, in root position, with the root on the ... There is only one way to play this triad. ...
    (rec.music.classical.guitar)
  • Re: Timeout during XmlSerializer instantiation
    ... application window rather than using the File -> Exit command. ... Could one of these methods cause this timeout more often ... access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, ... I would like to confirm my understanding of your issue. ...
    (microsoft.public.dotnet.xml)
  • Using streams/strings to parse data.
    ... I am reading data from a USB device using readFile: ... Since Readfile tells me how many bytes were copied into the buffer, ... Is it possible to intermix a series of gets and appends to a string ...
    (microsoft.public.vc.language)
  • Re: Using streams/strings to parse data.
    ... I am reading data from a USB device using readFile: ... Since Readfile tells me how many bytes were copied into the buffer, ... Is it possible to intermix a series of gets and appends to a string ...
    (microsoft.public.vc.language)