public static boolean isThisAGpsPort ( String port ) throws Exception { SerialPort comPort = SerialPort . getCommPort ( port ) ; comPort . openPort ( ) ; comPort . setComPortTimeouts ( SerialPort . TIMEOUT_READ_SEMI_BLOCKING , 100 , 0 ) ; int waitTries = 0 ; int parseTries = 0 ; while ( true && waitTries ++ < 10 && parseTries < 2 ) { while ( comPort . bytesAvailable ( ) == 0 ) Thread . sleep ( 500 ) ; byte [ ] readBuffer = new byte [ comPort . bytesAvailable ( ) ] ; int numRead = comPort . readBytes ( readBuffer , readBuffer . length ) ; if ( numRead > 0 ) { String data = new String ( readBuffer ) ; String [ ] split = data . split ( "\n" ) ; for ( String line : split ) { if ( SentenceValidator . isSentence ( line ) ) { return true ; } } parseTries ++ ; } } return false ; }
Makes a blocking check to find out if the given port supplies GPS data .