# HG changeset patch # User moel.mich # Date 1266356665 0 # Node ID 1d02fde1bb23710d842df1854ce1e74a11d2af54 # Parent f847947b7f8e5fb3ce0b41c0462b8804aa1804fa Restored CTSHolding check and added more report output for T-Balancer enumeration. diff -r f847947b7f8e -r 1d02fde1bb23 Hardware/Computer.cs --- a/Hardware/Computer.cs Mon Feb 15 22:58:29 2010 +0000 +++ b/Hardware/Computer.cs Tue Feb 16 21:44:25 2010 +0000 @@ -162,7 +162,7 @@ foreach (IGroup group in groups) { string report = group.GetReport(); - if (report != null) { + if (report != null && report != "") { NewSection(w); w.Write(report); } @@ -170,7 +170,7 @@ IHardware[] hardwareArray = group.Hardware; foreach (IHardware hardware in hardwareArray) { string hardwareReport = hardware.GetReport(); - if (hardwareReport != null) { + if (hardwareReport != null && hardwareReport != "") { NewSection(w); w.Write(hardwareReport); } diff -r f847947b7f8e -r 1d02fde1bb23 Hardware/TBalancer/TBalancerGroup.cs --- a/Hardware/TBalancer/TBalancerGroup.cs Mon Feb 15 22:58:29 2010 +0000 +++ b/Hardware/TBalancer/TBalancerGroup.cs Tue Feb 16 21:44:25 2010 +0000 @@ -56,54 +56,64 @@ SerialPort serialPort = new SerialPort(portNames[i], 19200, Parity.None, 8, StopBits.One); - serialPort.Open(); + bool isValid = false; byte protocolVersion = 0; report.Append("Port Name: "); report.AppendLine(portNames[i]); + try { + serialPort.Open(); + } catch (UnauthorizedAccessException) { + report.AppendLine("Exception: Access Denied"); + } + if (serialPort.IsOpen) { - serialPort.DiscardInBuffer(); - serialPort.DiscardOutBuffer(); - serialPort.Write(new byte[] { 0x38 }, 0, 1); - int j = 0; - while (serialPort.BytesToRead == 0 && j < 2) { - Thread.Sleep(100); - j++; - } - if (serialPort.BytesToRead > 0) { - if (serialPort.ReadByte() == TBalancer.STARTFLAG) { - while (serialPort.BytesToRead < 284 && j < 5) { - Thread.Sleep(100); - j++; - } - int length = serialPort.BytesToRead; - if (length >= 284) { - byte[] data = new byte[285]; - data[0] = TBalancer.STARTFLAG; - for (int k = 1; k < data.Length; k++) - data[k] = (byte)serialPort.ReadByte(); + if (serialPort.CtsHolding) { + serialPort.DiscardInBuffer(); + serialPort.DiscardOutBuffer(); + serialPort.Write(new byte[] { 0x38 }, 0, 1); + int j = 0; + while (serialPort.BytesToRead == 0 && j < 2) { + Thread.Sleep(100); + j++; + } + if (serialPort.BytesToRead > 0) { + if (serialPort.ReadByte() == TBalancer.STARTFLAG) { + while (serialPort.BytesToRead < 284 && j < 5) { + Thread.Sleep(100); + j++; + } + int length = serialPort.BytesToRead; + if (length >= 284) { + byte[] data = new byte[285]; + data[0] = TBalancer.STARTFLAG; + for (int k = 1; k < data.Length; k++) + data[k] = (byte)serialPort.ReadByte(); - // check protocol version 2X (protocols seen: 2C, 2A, 28) - isValid = (data[274] & 0xF0) == 0x20; - protocolVersion = data[274]; - if (!isValid) { - report.Append("Status: Wrong Protocol Version: 0x"); - report.AppendLine(protocolVersion.ToString("X")); + // check protocol version 2X (protocols seen: 2C, 2A, 28) + isValid = (data[274] & 0xF0) == 0x20; + protocolVersion = data[274]; + if (!isValid) { + report.Append("Status: Wrong Protocol Version: 0x"); + report.AppendLine(protocolVersion.ToString("X")); + } + } else { + report.AppendLine("Status: Wrong Message Length: " +length); } } else { - report.AppendLine("Status: Wrong Message Length: " + length); + report.AppendLine("Status: Wrong Startflag"); } } else { - report.AppendLine("Status: Wrong Startflag"); + report.AppendLine("Status: No Response"); } } else { - report.AppendLine("Status: No Response"); + report.AppendLine("Status: Not Clear to Send"); } - } else { + serialPort.DiscardInBuffer(); + serialPort.Close(); + } else { report.AppendLine("Status: Port not Open"); - } - serialPort.DiscardInBuffer(); - serialPort.Close(); + } if (isValid) { report.AppendLine("Status: OK"); hardware.Add(new TBalancer(portNames[i], protocolVersion)); @@ -111,8 +121,6 @@ } } catch (IOException ioe) { report.AppendLine(ioe.ToString()); - } catch (UnauthorizedAccessException uae) { - report.AppendLine(uae.ToString()); } catch (NullReferenceException ne) { report.AppendLine(ne.ToString()); } diff -r f847947b7f8e -r 1d02fde1bb23 Properties/AssemblyInfo.cs --- a/Properties/AssemblyInfo.cs Mon Feb 15 22:58:29 2010 +0000 +++ b/Properties/AssemblyInfo.cs Tue Feb 16 21:44:25 2010 +0000 @@ -69,5 +69,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.1.21.0")] -[assembly: AssemblyFileVersion("0.1.21.0")] +[assembly: AssemblyVersion("0.1.21.1")] +[assembly: AssemblyFileVersion("0.1.21.1")]