random0000
FabulaTech Forum Newbie
Posts: 1
|
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:utput_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; }
|