Click here to Skip to main content
15,899,124 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi friends,
I am new for C++. Please answer my questions
How to write a Multiple COM Port at same time? Is it Possible?How? Please give a Code
In My Program,I declared a Object like this
C++
struct _DCB dcb;
	HANDLE hCom; 

What is mean by INVALID_HANDLE_VALUE?
what is mean by SetupComm(hCom,16000,16000)?
what is mean by GetCommState(hCom,&dcb)?
what is mean by GetCommTimeouts(hCom,&commtime)?
what is mean by SetCommTimeouts(hCom,&commtime)?
Please answer my Questions.Thanks in Advance
Posted
Comments
Chandrasekharan P 16-Mar-12 4:18am    
Why is that you are not using Google before putting a query here. Search each functions individually in Google and open the first link. All you want is explained very clearly.

I'm sorry, but these are pretty simple questions to answer.
As it is, they look very strongly like your homework, and we don't do that for you! All of those could be answered very easily by a little bit of research on your part.

Google is your friend: Be nice and visit him often. He can answer questions a lot more quickly than posting them here...
 
Share this answer
 
Do you mean "how to write to multiple COM ports at the same time"?
Your code might open the ports and write the same data to all of them.

naraayanan wrote:
What is mean by INVALID_HANDLE_VALUE?
It is a special return value the CreateFile function uses to inform you that the call failed. You have to immediately call GetLastError to obtain a meaningful error code.


naraayanan wrote:
what is mean by SetupComm(hCom,16000,16000)?
Sets the sizes of the I/O buffers to 16000 bytes.


naraayanan wrote:
what is mean by GetCommState(hCom,&dcb)?
Retrieves the current value of the DCB[^] configuration struct.


naraayanan wrote:
what is mean by GetCommTimeouts(hCom,&commtime)?

naraayanan wrote:
what is mean by SetCommTimeouts(hCom,&commtime)?

Respectively gets and sets the current value of the COMMTIMEOUTS[^] struct. The struct contains the send/receive timeout parameters.



Serial port configuration (suggested) process works this way: retrieve all the current configuration parameters in a struct, change (on the struct) the values of the few parameters you are interested in, then, using such struct set all the parameters back.


BTW serial port programming on Windows isn't really a daunting task, however you have to read the documentation. MSDN provides some nice code samples as well, see, for instance: "Using Communications Resources"[^].
 
Share this answer
 
v2
Comments
Chandrasekharan P 16-Mar-12 5:13am    
5 for the effort.
CPallini 16-Mar-12 6:52am    
:-) Thank you.
It is possible to open multiple COM ports and write to them. It's not possible to open the same COM port multiple times (a COM port can't be opened if already opened by any application).

To open a COM port, use the CreateFile() [^] function:

C++
LPCTSTR lpszPort = _T("COM1");
HANDLE hCom = ::CreateFile(lpszPort, GENERIC_READ | GENERIC_WRITE,
    0, NULL, OPEN_EXISTING, 0, NULL);
if (INVALID_HANDLE_VALUE == hCom)
    AfxMessageBox(_T("Can't open COM port"));



INVALID_HANDLE_VALUE is returned by CreateFile() when opening the specified file or COM port fails (like trying to open a COM port that is already opened).

For the communication functions see the MSDN [^].
 
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