Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
#Introduction
First I would like to apologize for my bad English. I do not speak English and am using Google translator.
I need to develop a program in C ++ for windows. This program will control serial ports in my application.

#The problem
It is possible to get the settings as baud rate, parity, stop bit and other one serial port that is already open by another application? And how I do it?
I could easily get these settings through the CreateFile () function and GetCommState (), but the serial port already'll be open and I can not.

Could someone help me?
Posted

1 solution

Read it paying more attention: https://msdn.microsoft.com/en-us/library/aa450503.aspx.

Don't you see something strange? You never read "comm state" of anything physical. In the example, for example, you read defaults. How?

Here is the thing: the port itself does not have any particular state. It will do what you tell it to do. Generally, there is a little sense in reading it with GetCommState. You will read what is prescribed in some date of the software, either the defaults or the values you put there during your last call to SetCommState. And your whole question, likewise, makes little to no sense.

The communication parameters are the properties of some device on the other end of your RS-232 cable. Both devices, your computer and the remote one, should use matching parameters, that's all. You just need to know them in advance. If that remote device is another computer or some more or less advanced thing, you could have some protocol of starting with default values at low baud rate, negotiate over the use of optimal parameters (using data communicating through the channel and some common protocol for that) and then change the baud rate, and maybe handshake and something else. This is rarely used. More typically, you simply read from documentation what the other end requires and meet these requirements.

Sounds not very promising? But who told you that serial port communication is supposed to be something good? This is old trash based on the standard of 1997:
http://en.wikipedia.org/wiki/Serial_port,
http://en.wikipedia.org/wiki/RS-232.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900