diff -r 91edecb084a1 -r 3fdadd4a830f Hardware/TBalancer/TBalancer.cs --- a/Hardware/TBalancer/TBalancer.cs Fri Mar 26 20:58:10 2010 +0000 +++ b/Hardware/TBalancer/TBalancer.cs Sat Mar 27 12:57:09 2010 +0000 @@ -326,17 +326,23 @@ } public void Update() { - while (serialPort.BytesToRead >= 285) - ReadData(); - if (serialPort.BytesToRead == 1) - serialPort.ReadByte(); + try { + while (serialPort.IsOpen && serialPort.BytesToRead >= 285) + ReadData(); + if (serialPort.BytesToRead == 1) + serialPort.ReadByte(); - serialPort.Write(new byte[] { 0x38 }, 0, 1); - alternativeRequest.BeginInvoke(null, null); + serialPort.Write(new byte[] { 0x38 }, 0, 1); + alternativeRequest.BeginInvoke(null, null); + } catch (InvalidOperationException) { + foreach (Sensor sensor in active) + sensor.Value = null; + } } public void Close() { - serialPort.Close(); + if (serialPort.IsOpen) + serialPort.Close(); } public event SensorEventHandler SensorAdded;