Click here to Skip to main content
15,906,455 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Solution ot the following error Pin
ShilpiP21-Sep-07 1:43
ShilpiP21-Sep-07 1:43 
AnswerRe: Solution ot the following error Pin
David Crow21-Sep-07 3:01
David Crow21-Sep-07 3:01 
Questionhow to get port number Pin
p_20-Sep-07 23:37
p_20-Sep-07 23:37 
AnswerRe: how to get port number Pin
kakan21-Sep-07 0:42
professionalkakan21-Sep-07 0:42 
AnswerRe: how to get port number Pin
p_21-Sep-07 1:14
p_21-Sep-07 1:14 
GeneralRe: how to get port number Pin
David Crow21-Sep-07 2:57
David Crow21-Sep-07 2:57 
GeneralRe: how to get port number Pin
Dave Kreskowiak21-Sep-07 12:42
mveDave Kreskowiak21-Sep-07 12:42 
QuestionCOM port problems Pin
Cedric Moonen20-Sep-07 22:59
Cedric Moonen20-Sep-07 22:59 
Hello !

I was having some troubles with the use of COM ports on an embedded device (Pocket PC with windows mobile 5). I already opened a discussion here[^].

I finally decided to use WaitCommEvent to monitor incoming data but this doesn't seem to work as expected. The port that I'm working with is a virtual COM port which is provided by a Bluetooth stack when a Bluetooth connection is established. Here is the code:

int CSerialDriver::ReadData(char* szData, int MaxLenght)
{
	DWORD dwMask = 0;
	WaitCommEvent(m_hCOMPort,&dwMask,NULL);

	if (dwMask & EV_RXCHAR)
	{
		DWORD dwRead = 0;
		int Count = 0;
		do
		{
			Count = MaxLenght - BytesRead;
			ReadFile(m_hCOMPort,szData+BytesRead,Count,&dwRead,NULL);
			BytesRead += dwRead;
		} while ( dwRead && (BytesRead<MaxLenght) );
	}

	return BytesRead;
}


The comm mask is set when the port is opened:
SetCommMask(m_hCOMPort,EV_RXCHAR);


The problem that I encounter is that the WaitCommEvent doesn't work as expected: when I receive data, WaitCommEvent exit as expected but sometimes, all the data has not been received yet (which is logical). That's not a problem because my function will get called until all data has been received. The problem comes when I enter the function a second time and call WaitCommEvent, at this time it doesn't exit even if bytes have been received in between. Having read this article[^], WaitCommEvent should exit if bytes have been received in between.

Would it be possible that it is a bug in the driver supplied by the company that produce the Bluetooth stack ? Or did I do something wrong ?

Another question: it is stated in MSDN:
Only one WaitCommEvent can be used for each open COM port handle. This means that if you have three threads in your application and each thread needs to wait on a specific comm event, each thread needs to open the COM port and then use the assigned port handle for their respective WaitCommEvent calls. (see here[^])

So, that would mean that your application could open the COM port several time. I tried that on win32 but that doesn't work at all (each time I receive an invalid handle value and the GetLastError code is "Access is denied"). I tried with different access:

m_hCOMPortWrite = CreateFile(strPortName.c_str(),
				GENERIC_WRITE,
			        FILE_SHARE_READ | FILE_SHARE_WRITE,
			 	NULL,
				OPEN_EXISTING,
				0,
				NULL);

m_hCOMPortRead = CreateFile(m_strPortName.c_str(),
			GENERIC_READ ,
			FILE_SHARE_READ | FILE_SHARE_WRITE,
			NULL,
			OPEN_EXISTING,
			0,
			NULL);


Is there a difference here between win32 and windozs Mobile 5 ? Why do they state that you could open the port multiple time ?

Thanks in advance


Cédric Moonen
Software developer

Charting control [v1.2]

QuestionCalling java method from c++ ! stuck in between while invoking jvm! Pin
amitamit19820-Sep-07 22:50
amitamit19820-Sep-07 22:50 
AnswerRe: Calling java method from c++ ! stuck in between while invoking jvm! Pin
Cedric Moonen20-Sep-07 23:23
Cedric Moonen20-Sep-07 23:23 
AnswerRe: Calling java method from c++ ! stuck in between while invoking jvm! Pin
David Crow21-Sep-07 2:55
David Crow21-Sep-07 2:55 
QuestionHow to write in windows registry Pin
Exelioindia20-Sep-07 21:00
Exelioindia20-Sep-07 21:00 
AnswerRe: How to write in windows registry Pin
Llasus20-Sep-07 21:12
Llasus20-Sep-07 21:12 
GeneralRe: How to write in windows registry Pin
Exelioindia20-Sep-07 21:50
Exelioindia20-Sep-07 21:50 
GeneralRe: How to write in windows registry Pin
Llasus20-Sep-07 22:02
Llasus20-Sep-07 22:02 
GeneralRe: How to write in windows registry Pin
Exelioindia21-Sep-07 0:09
Exelioindia21-Sep-07 0:09 
QuestionRe: How to write in windows registry Pin
David Crow21-Sep-07 2:51
David Crow21-Sep-07 2:51 
AnswerRe: How to write in windows registry Pin
nbugalia20-Sep-07 21:28
nbugalia20-Sep-07 21:28 
GeneralRe: How to write in windows registry Pin
Exelioindia20-Sep-07 21:50
Exelioindia20-Sep-07 21:50 
AnswerRe: How to write in windows registry Pin
Hamid_RT20-Sep-07 21:57
Hamid_RT20-Sep-07 21:57 
AnswerRe: How to write in windows registry Pin
ThatsAlok20-Sep-07 23:08
ThatsAlok20-Sep-07 23:08 
AnswerRe: How to write in windows registry Pin
Rahul Vaishnav21-Sep-07 1:03
Rahul Vaishnav21-Sep-07 1:03 
GeneralRe: How to write in windows registry Pin
Exelioindia21-Sep-07 1:33
Exelioindia21-Sep-07 1:33 
GeneralRe: How to write in windows registry Pin
David Crow21-Sep-07 2:49
David Crow21-Sep-07 2:49 
General[Message Deleted] Pin
Californian221-Sep-07 5:57
Californian221-Sep-07 5:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.