Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. ERROR_OPERATION_ABORTED with serial comms

ERROR_OPERATION_ABORTED with serial comms

Scheduled Pinned Locked Moved C / C++ / MFC
helpcomsecurityquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jimjim733
    wrote on last edited by
    #1

    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:

    #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;
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups