Apr 19th, 2024, 12:22pm
Welcome, Guest. Please Login or Register.
Pages: 1  Reply Reply  Notify of replies Notify of replies  Print Print
   Author  Topic: Issue with NSP  (Read 3850 times)
random0000
FabulaTech Forum Newbie
*



View Profile         
Posts: 1
Issue with NSP
« on: Feb 14th, 2006, 3:44pm »
Quote Quote  Modify Modify

We recently purchased this software and are very impressed.  However we are running into an issue where existing code works fine over normal serial cables but not using the software.  
 
The code was written in c++ of which I am barely familiar with but I will post below.  Essentially we are sending a single byte ACK in response to a previous communication.  The below code loops indefinitely at the WaitForMultipleObjects.  Again this code works fine from a "real" serial port.
 
bool RWPort:Shockedutput_worker(BYTE c, RWPort *port)
{
  OVERLAPPED AsyncWriteInfo = { 0 };
  AsyncWriteInfo.hEvent = CreateEvent( NULL, true, false, NULL );
  assert( AsyncWriteInfo.hEvent );
  HANDLE handles[ 2 ] = { port->m_hKillInputThreadEvent,
      AsyncWriteInfo.hEvent };
  bool running = true;
  for ( bool done = false ; NOT done ; )  
 
{
    DWORD result_count = 0;
    if (NOT WriteFile( port->m_hPort, &c, 1, &result_count, &AsyncWriteInfo ) )  
 
 
{
 if ( GetLastError() EQ ERROR_IO_PENDING )  
 
 
 
{
   switch ( WaitForMultipleObjects( 2, handles, false, INFINITE ) )  
 
 
 
 
{
     case 0 : //m_hKillOutputThreadEvent
  done = true;  
  running = false;
  PurgeComm( port->m_hPort, PURGE_TXABORT );  
  break;
     case 1 : //AsyncWriteInfo.hEvent
  if ( NOT GetOverlappedResult( port->m_hPort, &AsyncWriteInfo, &result_count,
 
 
 
 
 
 
 
        false ) OR result_count NE 1 )  
 
 
 
 
 
 
{
    if ( GetLastError() EQ ERROR_IO_PENDING )
      port->clear_error();
    else
      port->translate_last_error();
    done = true;    
  }  
  break;
     default :
  assert( false );
   }
 }
 
 
 
else  
 
 
 
{
   port->translate_last_error();
   done = true;    
 }
    }
 
 
else  
 
 
{
 if ( result_count NE 1 )  
   port->translate_last_error();
 done = true;
    }
  }
  //
  // On the way out, close the event handle
  //
  CloseHandle( AsyncWriteInfo.hEvent );
  return running;
}
IP Logged
Andrew
FabulaTech Forum Moderator
Moderator
FabulaTech Forum Senior Member
*****



View Profile   WWW         
Gender: male Posts: 427
Re: Issue with NSP
« Reply #1 on: Feb 15th, 2006, 1:50am »
Quote Quote  Modify Modify

There is error in your below code:
 
    case 1 : //AsyncWriteInfo.hEvent  
  if ( NOT GetOverlappedResult( port->m_hPort, &AsyncWriteInfo, &result_count,  
   false ) OR result_count NE 1 )  
{  
    if ( GetLastError() EQ ERROR_IO_PENDING )  
 port->clear_error();  
    else  
 port->translate_last_error();  
    done = true;      
  }  
  break;
 
In your code fragment, flag "done" will not set and loop will not be breaked if GetOverlappedResult() function returns TRUE and "result_count" value will be 1. So correct code has to be:
 
case 1 : //AsyncWriteInfo.hEvent  
 if ( NOT GetOverlappedResult( port->m_hPort, &AsyncWriteInfo, &result_count,  
  false ) OR result_count NE 1 )  
{  
   if ( GetLastError() EQ ERROR_IO_PENDING )  
     port->clear_error();  
   else  
     port->translate_last_error();  
 }  
   done = true;     // <------------------------
 break;  
 
IP Logged

Andrew Scott

FabulaTech
===================
http://www.fabulatech.com
Pages: 1  Reply Reply  Notify of replies Notify of replies  Print Print

« Previous topic | Next topic »
Online Talk to our
support team or
sales department.