Note that there are some explanatory texts on larger screens.

plurals
  1. POReading Stream after using enableReceiveTimeout
    primarykey
    data
    text
    <p>I am currently working on a Java project, one of the aims of which is to display current position of the user on a map. After code completion, I realized that there is a possibility of the user unplugging the GPS device while the application is still running. On recreating the above scenario, I found that the application forever hangs at the code :</p> <pre><code>detectedGPSPortBufferReader.readLine(); </code></pre> <p>So, I went to the good old Java Docs and found the method <strong>enableReceiveTimeout()</strong> and everything works perfect. <em>(Value is 30000, 30 seconds)</em></p> <p>Now, I have managed to think of another scenario, wherein the user may re-plug the device back on. In this scenario, my clientele would want the device to start reading again. But unfortunately that ain't happening.</p> <p>I am working with my buddy "The Good Old Java Docs" and would love for any one of you geek gods to guide me on my journey.</p> <p>My Code :</p> <pre><code>try { myGPSConnector.detectedGPSPort.enableReceiveTimeout(3000); if(myGPSConnector.detectedGPSPortBufferReader.readLine() != null) { myGPSConnector.nmeaResponse = myGPSConnector.detectedGPSPortBufferReader.readLine(); System.out.println(myGPSConnector.nmeaResponse); } } catch (Exception e) { locationString = "GPS Device not detected."; } </code></pre> <p>@derrabink : It can be a different stream, cuz I tried to work with the following extension to my code :</p> <pre><code>try { myGPSConnector.detectedGPSPort.enableReceiveTimeout(3000); if(myGPSConnector.detectedGPSPortBufferReader.readLine() != null) { myGPSConnector.nmeaResponse = myGPSConnector.detectedGPSPortBufferReader.readLine(); System.out.println(defaultGPSConnector.nmeaResponse); } } catch (Exception e) { locationString = "GPS Device not detected."; try { defaultGPSConnector.detectedGPSPort.enableReceiveTimeout(30); } catch (UnsupportedCommOperationException e1) { System.out.println("UnsupportedCommOperationException"); } try { locationString = defaultGPSConnector.detectedGPSPortBufferReader.readLine(); } catch (IOException e1) { System.out.println("IOException "); } </code></pre> <p>And It always prints <strong>IOException</strong></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload