Subversion Repositories Programming Utils

Compare Revisions

Ignore whitespace Rev 106 → Rev 107

/trunk/JavaSerial/NativeCode/SerialPortImpl.c
1452,6 → 1452,11
struct port_descriptor* desc;
jint ret_val;
int stat;
#ifdef _WIN32
DWORD ret = 0;
OVERLAPPED overlap = {0};
int current_available = 0;
#endif
 
desc = get_port_descriptor( env, obj );
if( desc == NULL ){
1461,10 → 1466,37
ret_val = 0;
 
#ifdef _WIN32
if( !ReadFile( desc->port, &ret_val, 1, 0, 0) ){
throw_io_exception( env, GetLastError() );
return -1;
{
DWORD comErrors = {0};
COMSTAT portStatus = {0};
if( !ClearCommError( desc->port, &comErrors, &portStatus ) ){
//return value zero = fail
throw_io_exception( env, GetLastError() );
return -1;
}else{
current_available = portStatus.cbInQue;
}
}
if( !current_available ){
//If nothing is currently available, wait until we get an event of some kind.
//This could be the serial lines changing state, or it could be some data
//coming into the system.
overlap.hEvent = CreateEvent( 0, TRUE, 0, 0 );
SetCommMask( desc->port, EV_RXCHAR );
WaitCommEvent( desc->port, &ret, &overlap );
WaitForSingleObject( overlap.hEvent, INFINITE );
}else{
//Data is available; set the RXCHAR mask so we try to read from the port
ret = EV_RXCHAR;
}
if( ret & EV_RXCHAR ){
if( !ReadFile( desc->port, &ret_val, 1, &stat, &overlap) ){
throw_io_exception( env, GetLastError() );
return -1;
}
}
#else
pthread_mutex_lock( &(desc->in_use) );
stat = read( desc->port, &ret_val, 1 );