Re: 1 serial port 2 parity types? MFC based app needs assistance.




"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 all

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

Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm


.



Relevant Pages

  • Re: Cant read from serial port after RedHat reboot
    ... >flowcontrol and parity. ... since you've already opened the port with the O_NDELAY flag. ... If we look at the c_iflag member, ... POSIX says that a termios ...
    (comp.os.linux.misc)
  • Re: Xilinx ISE Inferred block rams
    ... but I write them with zero values so the port isn't undefined. ... parity bits but the write port output parity bits are unused. ... I tend to skip the post-translate simulation in favor of live testing except ...
    (comp.arch.fpga)
  • Re: OpenNETCF Serial not working in my WinCE 5.0 device
    ... A framing error indicates that the parity or the byte size is wrong, ... send the data and check the current settings for the port you're sending it ... > StopBits: One ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: 1 serial port 2 parity types? MFC based app needs assistance.
    ... Key here is that changing the parity is trivial: ... not need to close/reopen the port at all. ... CHARACTER IS PLACED IN THE OUTPUT REGISTER. ... The reciever is always receiving ODD parity. ...
    (microsoft.public.vc.mfc)
  • Reading COM port in Binary mode
    ... I am openning a COM port and reading data. ... is "Odd parity". ... When I read the data from the COM port the parity bit is ...
    (microsoft.public.win2000.developer)