Changed the T-Balancer detection and added more report details.
1.1 --- a/Hardware/TBalancer/TBalancerGroup.cs Fri Feb 12 00:36:56 2010 +0000
1.2 +++ b/Hardware/TBalancer/TBalancerGroup.cs Fri Feb 12 08:17:51 2010 +0000
1.3 @@ -59,11 +59,9 @@
1.4 serialPort.Open();
1.5 bool isValid = false;
1.6 byte protocolVersion = 0;
1.7 - if (serialPort.IsOpen && serialPort.CDHolding &&
1.8 - serialPort.CtsHolding) {
1.9 + report.Append("Port Name: "); report.AppendLine(portNames[i]);
1.10
1.11 - report.Append("Port Name: "); report.AppendLine(portNames[i]);
1.12 -
1.13 + if (serialPort.IsOpen) {
1.14 serialPort.DiscardInBuffer();
1.15 serialPort.DiscardOutBuffer();
1.16 serialPort.Write(new byte[] { 0x38 }, 0, 1);
1.17 @@ -72,34 +70,39 @@
1.18 Thread.Sleep(100);
1.19 j++;
1.20 }
1.21 - if (serialPort.BytesToRead > 0 &&
1.22 - serialPort.ReadByte() == TBalancer.STARTFLAG) {
1.23 - while (serialPort.BytesToRead < 284 && j < 5) {
1.24 - Thread.Sleep(100);
1.25 - j++;
1.26 - }
1.27 - int length = serialPort.BytesToRead;
1.28 - if (length >= 284) {
1.29 - byte[] data = new byte[285];
1.30 - data[0] = TBalancer.STARTFLAG;
1.31 - for (int k = 1; k < data.Length; k++)
1.32 - data[k] = (byte)serialPort.ReadByte();
1.33 + if (serialPort.BytesToRead > 0) {
1.34 + if (serialPort.ReadByte() == TBalancer.STARTFLAG) {
1.35 + while (serialPort.BytesToRead < 284 && j < 5) {
1.36 + Thread.Sleep(100);
1.37 + j++;
1.38 + }
1.39 + int length = serialPort.BytesToRead;
1.40 + if (length >= 284) {
1.41 + byte[] data = new byte[285];
1.42 + data[0] = TBalancer.STARTFLAG;
1.43 + for (int k = 1; k < data.Length; k++)
1.44 + data[k] = (byte)serialPort.ReadByte();
1.45
1.46 - // check protocol version
1.47 - isValid =
1.48 - data[274] == TBalancer.PROTOCOL_VERSION_2A ||
1.49 - data[274] == TBalancer.PROTOCOL_VERSION_2C;
1.50 - protocolVersion = data[274];
1.51 - if (!isValid) {
1.52 - report.Append("Status: Wrong Protocol Version: 0x");
1.53 - report.AppendLine(protocolVersion.ToString("X"));
1.54 + // check protocol version
1.55 + isValid =
1.56 + data[274] == TBalancer.PROTOCOL_VERSION_2A ||
1.57 + data[274] == TBalancer.PROTOCOL_VERSION_2C;
1.58 + protocolVersion = data[274];
1.59 + if (!isValid) {
1.60 + report.Append("Status: Wrong Protocol Version: 0x");
1.61 + report.AppendLine(protocolVersion.ToString("X"));
1.62 + }
1.63 + } else {
1.64 + report.AppendLine("Status: Wrong Message Length: " + length);
1.65 }
1.66 } else {
1.67 - report.AppendLine("Status: Wrong Message Length: " + length);
1.68 + report.AppendLine("Status: Wrong Startflag");
1.69 }
1.70 } else {
1.71 - report.AppendLine("Status: Wrong Startflag");
1.72 + report.AppendLine("Status: No Response");
1.73 }
1.74 + } else {
1.75 + report.AppendLine("Status: Port not Open");
1.76 }
1.77 serialPort.DiscardInBuffer();
1.78 serialPort.Close();
1.79 @@ -115,6 +118,7 @@
1.80 } catch (NullReferenceException ne) {
1.81 report.AppendLine(ne.ToString());
1.82 }
1.83 + report.AppendLine();
1.84 }
1.85 }
1.86
1.87 @@ -127,8 +131,7 @@
1.88 public string GetReport() {
1.89 if (report.Length > 0) {
1.90 report.Insert(0, "Serial Port T-Balancer" + Environment.NewLine +
1.91 - Environment.NewLine);
1.92 - report.AppendLine();
1.93 + Environment.NewLine);
1.94 return report.ToString();
1.95 } else
1.96 return null;
2.1 --- a/Properties/AssemblyInfo.cs Fri Feb 12 00:36:56 2010 +0000
2.2 +++ b/Properties/AssemblyInfo.cs Fri Feb 12 08:17:51 2010 +0000
2.3 @@ -69,5 +69,5 @@
2.4 // You can specify all the values or you can default the Build and Revision Numbers
2.5 // by using the '*' as shown below:
2.6 // [assembly: AssemblyVersion("1.0.*")]
2.7 -[assembly: AssemblyVersion("0.1.18.0")]
2.8 -[assembly: AssemblyFileVersion("0.1.18.0")]
2.9 +[assembly: AssemblyVersion("0.1.18.1")]
2.10 +[assembly: AssemblyFileVersion("0.1.18.1")]