title: Detecting Serial port disconnect in Chrome App
body: <p>I'm using Chrome's Serial Port API (<a href="http://developer.chrome.com/apps/serial.html" rel="nofollow">http://developer.chrome.com/apps/serial.html</a>) in a Web App.</p>
  
  <p>The problem I have is that pretty much all serial ports now are implemented via USB devices. If the user disconnects (or just resets) the USB device, I don't have any way of knowing. Not only that, because the app hasn't disconnected in Chrome (because it didn't know), if the USB device is plugged back in, bad things happen (on Linux it just gets a different name, but in Windows it is not usable at all).</p>
  
  <p>The best I can manage is:</p>
  
  <pre><code>  var checkConnection = function() {
      chrome.serial.getControlSignals(connectionInfo.connectionId, function (sigs) { 
        var connected = "cts" in sigs;
        if (!connected) console.log("Disconnected");
     });
    } // called every second or so
  </code></pre>
  
  <p>Is there a better way? a callback would be ideal!</p>