Re: 1 serial port 2 parity types? MFC based app needs assistance.
- From: "nappy" <n@xxx>
- Date: Fri, 4 Jul 2008 10:23:49 -0700
"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> wrote in message
news:kojs645btq2vdddoti6sdf4k48gc0l9cto@xxxxxxxxxx
Well, this does present a problem, sort of.
Key here is that changing the parity is trivial: SetCommState. You just
set the desired
parity in the DCB structure (use GetCommState to fill it in each time) and
set it. You do
not need to close/reopen the port at all.
The glitch is *when* to set it.
The problem is that SetCommState happens IMMEDIATELY. But due to
fundamental brain damage
in the design, you get the notification of "completing" the output
operation WHEN THE LAST
CHARACTER IS PLACED IN THE OUTPUT REGISTER. Of course, this is completely
wrong, because
the last character has not yet been TRANSMITTED, so if you immediately
change the state,
you will set the state WHILE the last character is being transmitted,
which tends to
garbage it. Apparently, it never occured to Microsoft to consider that
data is not sent
until it is sent. Placing a character in the output register is *not* the
same as
"sending" it.
Exactly. thanks for the reply Joe. This is exactly how I assumed it.
The expert on this, Egberto Willies, (www.wcsc.net) used to sell serial
port drivers that
did the right thing (meaning: it wasn't impossible to do). One client I
did work for
would have been required to send out a driver with every copy of their
program, which they
felt was too much of a tech support burden, so what I ended up doing was,
after receiving
the notification of the "completion" (alleged) of the output, I did a
Sleep(10) to give
the character time to be sent, before changing any state in the DCB. THEN
I had the
problem that if I delayed too long, the remote device would already start
sending data,
and I'd lose it. So I set the inter-character timeout to 200ms (it has to
be very long)
and ran the thread elevated 2 points in priority; the combination of these
tricks gave me
the responsiveness I needed to make it work. An ugly solution, one that
would not have
been necessary had the drivers been written correctly, but one which
seemed to solve the
problem.
joe
Dang. Exactly the problems I had aniticpated. With respect to the remote
device sending data while the device is in the wrong mode.
I am ready to suggest to the client (NAVY subcontractor) that we use a bit
from the paralell port to switch between tow transmit lines form two
different serial ports. Only switch right before you send. Never after. The
receive would always be the same line..
Otherwise I've got to try and use a timer or something? Take the number of
characters being sent and mult times the baud rate with parity and stop bits
added in..
But that is not going to be 100% dependable .. I do not think.
How long does it take Windows to actually start shifting bits out ? Is it
unknown and un knowable?
Thanks
Nappy
On Fri, 4 Jul 2008 08:39:05 -0700, "nappy" <n@xxx> wrote:
Hello allJoseph M. Newcomer [MVP]
I am workiing in MFC on an app which has an odd requirement.. for me
anyway.
I have only one serial port availbale. The task is that one portion of my
GUI has to send serial data out with EVEN parity. The other, a keypad, has
to send serial data out with ODD parity.
The reciever is always receiving ODD parity.
So.. unless I am wrong.. I am thinking I have to switch to ODD parity
before
sending out keypad strings and tehn, when the last character is shifted
out
I hvae to set the port back to even parity in time to get the host's
response.
Anyone have any ideas?
How do I query the actual output buffers of a port?
Can I set the com port's parity without closing and reopening the port?
Is this even the correct way to do it?
Thanks in advance
jona
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- Follow-Ups:
- Re: 1 serial port 2 parity types? MFC based app needs assistance.
- From: Bill Snyder
- Re: 1 serial port 2 parity types? MFC based app needs assistance.
- From: Scott McPhillips [MVP]
- Re: 1 serial port 2 parity types? MFC based app needs assistance.
- References:
- 1 serial port 2 parity types? MFC based app needs assistance.
- From: nappy
- Re: 1 serial port 2 parity types? MFC based app needs assistance.
- From: Joseph M . Newcomer
- 1 serial port 2 parity types? MFC based app needs assistance.
- Prev by Date: Re: Problem in Float Arithmetic
- Next by Date: Re: Problem in Float Arithmetic
- Previous by thread: Re: 1 serial port 2 parity types? MFC based app needs assistance.
- Next by thread: Re: 1 serial port 2 parity types? MFC based app needs assistance.
- Index(es):
Relevant Pages
|