Windows serial port driver bugs/caveats???

Posted on 2002-06-07
Last Modified: 2013-11-15
I'm getting "interesting" behavior from the Windows serial port driver that I need to resolve. It involves
multiple things:

1. It seems to me that some of the DCB members are ignored during the opening of a COM port with CreateFile.
I am seeing the following behavior:

I call SetDefaultCommConfig( "COM1", &cfg, &dwSize ) with

cfg.dcb.fRtsControl = RTS_CONTROL_ENABLE;
cfg.dcb.fDtrControl = DTR_CONTROL_ENABLE;

and then call CreateFile( "COM1", ... )

However, CreateFile still disables the RTS and DTR lines automatically (sets them to logic 1).

2. Things get weirder once you call a GetCommState( &dcb ) which, even though the DTR line is disabled
(negative voltage read on voltmeter = logic 1, but DTR is active low) reports that

dcb.fDtrControl = DTR_CONTROL_ENABLE

By then calling SetCommState right after that (without modifying anything, ie:

GetCommState( &dcb );
SetCommState( &dcb );

all of a sudden DTR and RTS go active (according to GetCommState RTS == RTS_CONTROL_TOGGLE in spite
of what I tried to set with SetDefaultCommConfig)


Basically what I *NEED* is that when I call CreateFile( "COM1", ... ) the RTS line is NOT dropped to
a negative voltage (logic 1) automatically.

I'd also like some insight into the above-described behavior if anyone has any.

Thank you very much.



PS I'm on WinMe but I'm getting similar behavior from other Win9x based systems.

(A copy of this question is also posted in the MFC section.)

Question by:jdyer
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 49

Accepted Solution

DanRollins earned 300 total points
ID: 7064111
I have seen oddities, specifically, a port ignoring some DCB settings in calls to SetCommState.

This seems to occur most often in the 'virtual' ports that are associated with WinModems.  My guess is that the device driver writers were not too careful in implementing all options because they assume that only their modem driver will access the port.

We worked around the problem by setting the defaults for the port using the control panel Device Manager.  Perhaps if you set the default to Flow Control Xon/Xoff or None, the behavior would cease.

These are random ideas, but it sounds like you need some...
Perhaps some third-party vendor has replaced the standard Serial port device driver with some screwball kludge of random opcodes (though the programmers are probably proud of it).  This is not uncommon in Win9x if a legacy app has ever been installed.

Check the driver version and so forth in Device Manager.  Remove the driver and let Plug-n-Play detect it and reinstall the default driver.

Perhaps there is a TAPI monitor that thinks it owns that port.  Disable all fax software and all RAS software that monitors for incoming calls.

If you use EscapeCommFunction to set/clear RTS directly after opening... Does the brief moment of incorrect state cause your hardware a problem?   Can you just ground the pin or something to ignore its state?

-- Dan

Author Comment

ID: 7064614

I shouldn't have a TAPI monitor on that COM1 line just because of the fact that I use a cable modem and don't have any dial-up networking or anything related to it loaded.

I can recheck the device driver, but I've seen some fairly consistent behavior on a fairly wide variety of laptops.

Unfortunately the brief incorrect state is screwing me because the power to a microcontroller in my electronics is tied to that line, so anytime the RTS line gets even briefly dropped it dies (unfortunately no one placed a time-delay capacitor on that line to make it more resistant to quick changes in voltage)

Thanks for your ideas... I appreciate it.

Let me know if you have any more.



LVL 49

Expert Comment

ID: 7064638
Does setting the port defaults in the control panel -- before opening the port -- have any effect?

What parameters are you using in the CreateFile API?

Have you tried various (seemingly random) settings in the SetDefaultCommConfig API? I suggest working through each setting to see if anything at all has some effect on the behavior.

It might be interesting to know if it is a Windows thing.  Are there any experiments you can try in a non-Windows environment to determine new facts?

-- Dan
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

LVL 49

Expert Comment

ID: 7064639
Is there a modem on that port or on the computer?  If so, if you disable it or remove it, does that affect the behavior seen?
-- Dan
LVL 49

Expert Comment

ID: 7064798
Try opening for just GENERIC_READ or just GENERIC_WRITE.  see if that affects the situation.

Or try with dwDesiredAcess set to 0 for fun.  Here is some useful info from

The RTS line is controlled by the DTE.
If the fRtsControl member of the DCB is set to RTS_CONTROL_HANDSHAKE, the following flow control is used: If the input buffer has enough room to receive data (at least half the buffer is empty), the driver sets the RTS line high. If the input buffer has little room for incoming data (less than a quarter of the buffer is empty), the driver sets the RTS line low.

If the fRtsControl member of the DCB is set to RTS_CONTROL_TOGGLE, the driver sets the RTS line high when data is available for sending. The driver sets the line low when no data is available for sending. Windows 95 ignores this value and treats it the same as RTS_CONTROL_ENABLE.

If the fRtsControl member of the DCB is set to RTS_CONTROL_ENABLE or RTS_CONTROL_DISABLE, the application is free to change the state of the line as it needs. Note that in this case, the state of the line does not affect reception.

The DCE will suspend transmission when the line goes low. The DCE will resume transmission when the line goes high.
I'm confused as to high and loaw and 1 and 0, etc, but it seems to me that the driver controls this based upon the size of the available buffer.  Perhaps if you make the buffer really small or something, it will have an effect.  I recall something about setting the size of the internal comm buffer, but I'm just thrashing around in the dark...

--- Dan

Author Comment

ID: 7067333

I appreciate all of your ideas with this. I will try with just GENERIC_READ and GENERIC_WRITE access, unfortunately I need a full-duplex channel.

There is an internal modem, but not on that COM port (it's a laptop).

I have played with SetDefaultCommConfig without any luck.

CreateFile( "COM1",
            (HANDLE)NULL )

is my call.

Let me know if you have any other ideas... in the meantime, I'll try a GENERIC_READ separate, and a GENERIC_WRITE separate.

LVL 49

Expert Comment

ID: 7068538
If you open the port, then close it, then open it again perhaps the device will respond differently.  Just a thought.

-- Dan

Author Comment

ID: 7070433

Yes it does respond differently if you do a CloseHandle with the current settings. It seems to reopen them that way.

I did notice that driver 4.10.1998 seems to work correctly on another laptop I have at my disposal, while this one (which has 4.30.3000) does NOT work correctly.

4.30.2000 seems to be the more recent driver, meaning that Microsoft has screwed it up between versions 4.10.1998 and 4.90.3000. [Not that this is a HUGE surprise, but anyway]


LVL 49

Expert Comment

ID: 7070857
I hope that I have been some of some small assistance in helping you to diagnose your problems.

-- Dan
LVL 11

Expert Comment

ID: 7261622
Dear jdyer

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to accept


comment(s) as an answer.


Expert Comment

ID: 7332907
Force accepted

** Mindphaser - Community Support Moderator **

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Skype is a P2P (Peer to Peer) instant messaging and VOIP (Voice over IP) service – as well as a whole lot more.
In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question