Re: strange problem with serial communication
From: Maverick (Maverick_at_maverick.com)
Date: 12/27/04
- Next message: Steve Maillet \(eMVP\): "Re: A question about TFAT"
- Previous message: Maverick: "Re: strange problem with serial communication"
- In reply to: Scott McPhillips [MVP]: "Re: strange problem with serial communication"
- Messages sorted by: [ date ] [ thread ]
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]
>
- Next message: Steve Maillet \(eMVP\): "Re: A question about TFAT"
- Previous message: Maverick: "Re: strange problem with serial communication"
- In reply to: Scott McPhillips [MVP]: "Re: strange problem with serial communication"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|