Solved

Windows serial port driver bugs/caveats???

Posted on 2002-06-07
11
888 Views
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.

Regards,

jdyer

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.)

0
Comment
Question by:jdyer
11 Comments
 
LVL 49

Accepted Solution

by:
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
0
 
LVL 1

Author Comment

by:jdyer
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.

Regards,

jdyer

0
 
LVL 49

Expert Comment

by:DanRollins
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
0
 
LVL 49

Expert Comment

by:DanRollins
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
0
 
LVL 49

Expert Comment

by:DanRollins
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 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwbgen/html/msdn_serial.asp

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
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 1

Author Comment

by:jdyer
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",
            GENERIC_READ | GENERIC_WRITE,
            0,
            NULL,
            OPEN_EXISTING,
            0,
            (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.

0
 
LVL 49

Expert Comment

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

-- Dan
0
 
LVL 1

Author Comment

by:jdyer
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]

Anyway...

jdyer
0
 
LVL 49

Expert Comment

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

-- Dan
0
 
LVL 11

Expert Comment

by:griessh
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

     "DanROllins"

comment(s) as an answer.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 6

Expert Comment

by:Mindphaser
ID: 7332907
Force accepted

** Mindphaser - Community Support Moderator **
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
If your app took Google’s lash recently, here are the 5 most likely reasons.
Video by: Tony
This video teaches viewers how to export a project from Adobe Premiere Pro and the various file types involved.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

708 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now