Click here to Skip to main content
15,898,373 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Setting Font with Rich Edit Pin
Iain Clarke, Warrior Programmer17-Feb-09 22:47
Iain Clarke, Warrior Programmer17-Feb-09 22:47 
Questionproblem with adding items using CTreeCtrl class Pin
bhanu_reddy0916-Feb-09 1:00
bhanu_reddy0916-Feb-09 1:00 
AnswerRe: problem with adding items using CTreeCtrl class - PREPOST! Pin
Iain Clarke, Warrior Programmer16-Feb-09 2:14
Iain Clarke, Warrior Programmer16-Feb-09 2:14 
JokeRe: problem with adding items using CTreeCtrl class - PREPOST! Pin
SandipG 16-Feb-09 4:38
SandipG 16-Feb-09 4:38 
QuestionCombo box problem Pin
SRKSHOME16-Feb-09 0:58
SRKSHOME16-Feb-09 0:58 
AnswerRe: Combo box problem Pin
CPallini16-Feb-09 1:45
mveCPallini16-Feb-09 1:45 
AnswerRe: Combo box problem Pin
perle116-Feb-09 4:44
perle116-Feb-09 4:44 
QuestionERROR_OPERATION_ABORTED with serial comms Pin
jimjim73316-Feb-09 0:28
jimjim73316-Feb-09 0:28 
Hi there,

I have created a thread that just monitors the serial port, but as soon as the com port receives any data, the GetOverlappedResult issues an ERROR_OPERATION_ABORTED error.
Please can you take a look at my code, I cannot see what is going on.

Thanks

Jim Confused | :confused:

#define READ_TIMEOUT	500 // Milliseconds

UINT CPageOneDialog::monitorPTZThread(LPVOID pParam)
{
	DWORD		dwRead, dwRes;
	BOOL		fWaitingOnRead = FALSE;
	OVERLAPPED	osReader = {0};
	char ptzControlCommPort[14];
	struct PTZCommStruct *pPTZStruct = (struct PTZCommStruct *)pParam;


	// Open the comm port.
	sprintf(ptzControlCommPort,"\\\\.\\COM%d",PTZCTRLPORT+1);
	pPTZStruct->hPTZSerial = CreateFile( ptzControlCommPort,
				  GENERIC_READ | GENERIC_WRITE,
				  0,    // must be opened with exclusive-access
				  NULL, // no security attributes
				  OPEN_EXISTING, // must use OPEN_EXISTING
				  FILE_FLAG_OVERLAPPED,    // overlapped I/O
				  NULL  // hTemplate must be NULL for comm devices
				  );
	
	
	// Create the overlapped event.
	osReader.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);

	if(osReader.hEvent == NULL)
	{
		// Error creatiing overlapped event, abort.
		pPTZStruct->pWnd->PostMessage(UWM_READER_SHUTTING_DOWN);
		return 0;
	} 

	while(pPTZStruct->nPTZCommTerminate == 0)
	{
		if(!fWaitingOnRead)
		{
			// Issue read Operation.
			if(!ReadFile(pPTZStruct->hPTZSerial,PTZbuffer, MAX_BUFFER_SIZE, &dwRead, &osReader))
			{
				if(GetLastError() != ERROR_IO_PENDING) // read not delayed
				{
					// Error in comms - report!!!
					return 0;
				}
				else
				{
					fWaitingOnRead = TRUE;
				}
			}
			else
			{
				// ***Read the data
			}
		}
		else
		{
			dwRes = WaitForSingleObject(osReader.hEvent, READ_TIMEOUT);
			switch(dwRes)
			{
				// Read Completed
			case WAIT_OBJECT_0:
				if(!GetOverlappedResult(pPTZStruct->hPTZSerial, &osReader, &dwRead, FALSE))
				{
					DWORD dwError = GetLastError();
					switch(dwError)
					{
						case ERROR_HANDLE_EOF:
							return 0;
							break;
						case ERROR_IO_PENDING:
							return 0;
							break;
						case ERROR_IO_INCOMPLETE:
							return 0;
							break;
						case ERROR_OPERATION_ABORTED:
							return 0;
							break;
						default:
							// error in comms - report
							Dump1("Serial Read Error %d\r\n", ::GetLastError());
							return 0;
							break;
					}
				}
				else
				{
					// ***Read the Data 
				}
				fWaitingOnRead = FALSE;
				break;

			case WAIT_TIMEOUT:
				// Operation isn't complete yet. 				
break;

			default:
				// Error in the WaitForSigleObject; abort!!!!

				return 0;
				break;

			}
		}
	}
	return 0;
}

QuestionAfxMessageBox with Bold text Pin
sunny_vc16-Feb-09 0:04
sunny_vc16-Feb-09 0:04 
JokeRe: AfxMessageBox with Bold text Pin
CPallini16-Feb-09 0:28
mveCPallini16-Feb-09 0:28 
GeneralRe: AfxMessageBox with Bold text Pin
sunny_vc16-Feb-09 0:31
sunny_vc16-Feb-09 0:31 
AnswerRe: AfxMessageBox with Bold text Pin
Code-o-mat16-Feb-09 0:42
Code-o-mat16-Feb-09 0:42 
AnswerRe: AfxMessageBox with Bold text Pin
Hamid_RT16-Feb-09 0:58
Hamid_RT16-Feb-09 0:58 
GeneralRe: AfxMessageBox with Bold text Pin
sunny_vc16-Feb-09 1:20
sunny_vc16-Feb-09 1:20 
AnswerRe: AfxMessageBox with Bold text Pin
Iain Clarke, Warrior Programmer16-Feb-09 2:25
Iain Clarke, Warrior Programmer16-Feb-09 2:25 
QuestionUsing CMFCMenuBar with CDialog Pin
Shashikant_200615-Feb-09 23:10
Shashikant_200615-Feb-09 23:10 
AnswerRe: Using CMFCMenuBar with CDialog Pin
Gan Chuanli2-Nov-11 20:14
Gan Chuanli2-Nov-11 20:14 
QuestionHow can handle Wnd+D in Application? Pin
Le@rner15-Feb-09 22:37
Le@rner15-Feb-09 22:37 
AnswerRe: How can handle Wnd+D in Application? Pin
Iain Clarke, Warrior Programmer15-Feb-09 23:30
Iain Clarke, Warrior Programmer15-Feb-09 23:30 
GeneralRe: How can handle Wnd+D in Application? Pin
CPallini16-Feb-09 0:00
mveCPallini16-Feb-09 0:00 
JokeRe: How can handle Wnd+D in Application? Pin
Iain Clarke, Warrior Programmer16-Feb-09 0:15
Iain Clarke, Warrior Programmer16-Feb-09 0:15 
AnswerRe: How can handle Wnd+D in Application? Pin
Taran915-Feb-09 23:40
Taran915-Feb-09 23:40 
GeneralRe: How can handle Wnd+D in Application? Pin
Le@rner15-Feb-09 23:50
Le@rner15-Feb-09 23:50 
GeneralRe: How can handle Wnd+D in Application? Pin
Taran916-Feb-09 6:10
Taran916-Feb-09 6:10 
GeneralRe: How can handle Wnd+D in Application? Pin
Le@rner28-Feb-09 1:58
Le@rner28-Feb-09 1:58 

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.