How to set Flow Control setting for System Com Port

Hey,
I am working on this project where when a user selects a particular com port via a config dialog, the software needs to retrieve the OS COM Port settings for the particaul port that was selected. For example, If I select COM Port 1 on the config dialog in project, the software needs to retrieve the OS current COM Port 1 settings(Baud Rate, Data bits,Parity, Stop bit, and Flow Control). Once OS settings are retrieved, I neeed to update my project dialog with the OS COM Port Settings. Once dialog settings are updated to OS COM Port settings, users will have an opportuntiy to change current port settings by clicking a button. Once user has changed settings for a port,the OS COM Port current settings needs to be updated to what user input. As of now, the above is working for all settings except Flow Control by using CreateFile(),SetCommState(),and GetCommState(). However, the DCB struct does not have a member for the Flow Control setting, well as far as I can tell. With this in mind, how can I retrieve/set Flow Control settings for system com port. The following are the possible settings for Flow Control:Xon/Xoff, Hardware, None.

Thanks In Advance
Bobdabilder,
Thanks for your response. However, values for dcb.fDtrControl(DTR_CONTROL_DISABLE,DTR_CONTROL_ENABLE, and DTR_CONTROL_HANDSHAKE) on link doesn't match(well to me, don't know much about Flow Control) the Flow Control options(None, Xon/Xoff, Hardware) for System Com Port. With this in mind, is it ok to assume the following:
DTR_CONTROL_DISABLE = None
DTR_CONTROL_ENABLE = Xon/Xoff
DTR_CONTROL_HANDSHAKE = Hardware

Also when typing mode at the command prompt to get the current port settings, I do not see the Flow Control setting. The following are the port settings that are shown:
Baud
Parity
Data Bits
Stop Bits
Timeout
XON/XOFF
CTS handshaking
DSR handshaking
DSR sensitivity
DTR circuit
RTS circuit

At this time, I would like to know if one of the above settings is actually Flow Control.

Any Help will be greatly appreciated.
Ok, I'll give you my research on this. The command prompt com settings and the control panel device settings are different. the control panel settings are stored in the registry while the command line settings get reset at each reboot according to microsoft.
The following dcb structure members should be zero if not one of the two cases
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 char* flowControl = "xon/xoff";
            if ( flowControl == "hardware" ){
            			dcb.fOutX = false;
                        dcb.fInX = false;
                        dcb.fOutxCtsFlow = true;
                        dcb.fOutxDsrFlow = true;
                        dcb.fDsrSensitivity = true;
                        dcb.fRtsControl = RTS_CONTROL_HANDSHAKE;
                        dcb.fDtrControl = DTR_CONTROL_HANDSHAKE;
            }else if ( flowControl == "xon/xoff" ){
                        dcb.fOutX = true;
                        dcb.fInX = true;
                        dcb.fOutxCtsFlow = false;
                        dcb.fOutxDsrFlow = false;
                        dcb.fDsrSensitivity = false;
                        dcb.fRtsControl = RTS_CONTROL_DISABLE;
                        dcb.fDtrControl = DTR_CONTROL_DISABLE;
            }

            //set the port configuration
            if ( !SetCommState(hCommPort, &dcb) ){
                  cout << "Error - could not set comm port dcb configuration" << endl;
                  return false;
            }
			
			if(hCommPort)
			{
				CloseHandle(hCommPort);
			}


I have tested these in the command prompt. if you want to modify the registry value: I found it at
 
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ports

mine was com1
if the string value ends in a blank, it is none
if the string value ends in x, it is xon/xoff
if the string value ends in p, it is hardware

Hope this helps. Please double check. this is win7 32 bit machine.

edit: added link
http://support.microsoft.com/kb/112841
Last edited on
On the system where you set up flow control, become superuser or assume the equivalent root role.
Topic archived. No new replies allowed.