Restored CTSHolding check and added more report output for T-Balancer enumeration.

This commit is contained in:
Michael Möller 2010-02-16 21:44:25 +00:00
parent dc9108ade1
commit b43e33cb4f
3 changed files with 48 additions and 40 deletions

View File

@ -162,7 +162,7 @@ namespace OpenHardwareMonitor.Hardware {
foreach (IGroup group in groups) { foreach (IGroup group in groups) {
string report = group.GetReport(); string report = group.GetReport();
if (report != null) { if (report != null && report != "") {
NewSection(w); NewSection(w);
w.Write(report); w.Write(report);
} }
@ -170,7 +170,7 @@ namespace OpenHardwareMonitor.Hardware {
IHardware[] hardwareArray = group.Hardware; IHardware[] hardwareArray = group.Hardware;
foreach (IHardware hardware in hardwareArray) { foreach (IHardware hardware in hardwareArray) {
string hardwareReport = hardware.GetReport(); string hardwareReport = hardware.GetReport();
if (hardwareReport != null) { if (hardwareReport != null && hardwareReport != "") {
NewSection(w); NewSection(w);
w.Write(hardwareReport); w.Write(hardwareReport);
} }

View File

@ -56,54 +56,64 @@ namespace OpenHardwareMonitor.Hardware.TBalancer {
SerialPort serialPort = SerialPort serialPort =
new SerialPort(portNames[i], 19200, Parity.None, 8, StopBits.One); new SerialPort(portNames[i], 19200, Parity.None, 8, StopBits.One);
serialPort.Open();
bool isValid = false; bool isValid = false;
byte protocolVersion = 0; byte protocolVersion = 0;
report.Append("Port Name: "); report.AppendLine(portNames[i]); report.Append("Port Name: "); report.AppendLine(portNames[i]);
try {
serialPort.Open();
} catch (UnauthorizedAccessException) {
report.AppendLine("Exception: Access Denied");
}
if (serialPort.IsOpen) { if (serialPort.IsOpen) {
serialPort.DiscardInBuffer(); if (serialPort.CtsHolding) {
serialPort.DiscardOutBuffer(); serialPort.DiscardInBuffer();
serialPort.Write(new byte[] { 0x38 }, 0, 1); serialPort.DiscardOutBuffer();
int j = 0; serialPort.Write(new byte[] { 0x38 }, 0, 1);
while (serialPort.BytesToRead == 0 && j < 2) { int j = 0;
Thread.Sleep(100); while (serialPort.BytesToRead == 0 && j < 2) {
j++; Thread.Sleep(100);
} j++;
if (serialPort.BytesToRead > 0) { }
if (serialPort.ReadByte() == TBalancer.STARTFLAG) { if (serialPort.BytesToRead > 0) {
while (serialPort.BytesToRead < 284 && j < 5) { if (serialPort.ReadByte() == TBalancer.STARTFLAG) {
Thread.Sleep(100); while (serialPort.BytesToRead < 284 && j < 5) {
j++; Thread.Sleep(100);
} j++;
int length = serialPort.BytesToRead; }
if (length >= 284) { int length = serialPort.BytesToRead;
byte[] data = new byte[285]; if (length >= 284) {
data[0] = TBalancer.STARTFLAG; byte[] data = new byte[285];
for (int k = 1; k < data.Length; k++) data[0] = TBalancer.STARTFLAG;
data[k] = (byte)serialPort.ReadByte(); for (int k = 1; k < data.Length; k++)
data[k] = (byte)serialPort.ReadByte();
// check protocol version 2X (protocols seen: 2C, 2A, 28) // check protocol version 2X (protocols seen: 2C, 2A, 28)
isValid = (data[274] & 0xF0) == 0x20; isValid = (data[274] & 0xF0) == 0x20;
protocolVersion = data[274]; protocolVersion = data[274];
if (!isValid) { if (!isValid) {
report.Append("Status: Wrong Protocol Version: 0x"); report.Append("Status: Wrong Protocol Version: 0x");
report.AppendLine(protocolVersion.ToString("X")); report.AppendLine(protocolVersion.ToString("X"));
}
} else {
report.AppendLine("Status: Wrong Message Length: " +length);
} }
} else { } else {
report.AppendLine("Status: Wrong Message Length: " + length); report.AppendLine("Status: Wrong Startflag");
} }
} else { } else {
report.AppendLine("Status: Wrong Startflag"); report.AppendLine("Status: No Response");
} }
} else { } 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"); report.AppendLine("Status: Port not Open");
} }
serialPort.DiscardInBuffer();
serialPort.Close();
if (isValid) { if (isValid) {
report.AppendLine("Status: OK"); report.AppendLine("Status: OK");
hardware.Add(new TBalancer(portNames[i], protocolVersion)); hardware.Add(new TBalancer(portNames[i], protocolVersion));
@ -111,8 +121,6 @@ namespace OpenHardwareMonitor.Hardware.TBalancer {
} }
} catch (IOException ioe) { } catch (IOException ioe) {
report.AppendLine(ioe.ToString()); report.AppendLine(ioe.ToString());
} catch (UnauthorizedAccessException uae) {
report.AppendLine(uae.ToString());
} catch (NullReferenceException ne) { } catch (NullReferenceException ne) {
report.AppendLine(ne.ToString()); report.AppendLine(ne.ToString());
} }

View File

@ -69,5 +69,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.1.21.0")] [assembly: AssemblyVersion("0.1.21.1")]
[assembly: AssemblyFileVersion("0.1.21.0")] [assembly: AssemblyFileVersion("0.1.21.1")]