1.1 --- a/Hardware/Heatmaster/HeatmasterGroup.cs Sun Aug 22 21:53:11 2010 +0000
1.2 +++ b/Hardware/Heatmaster/HeatmasterGroup.cs Mon Aug 23 20:00:06 2010 +0000
1.3 @@ -38,8 +38,10 @@
1.4 using System;
1.5 using System.Collections.Generic;
1.6 using System.IO.Ports;
1.7 +using System.Security;
1.8 using System.Text;
1.9 using System.Threading;
1.10 +using Microsoft.Win32;
1.11
1.12 namespace OpenHardwareMonitor.Hardware.Heatmaster {
1.13 internal class HeatmasterGroup : IGroup {
1.14 @@ -63,11 +65,36 @@
1.15 Thread.Sleep(1);
1.16 }
1.17 throw new TimeoutException();
1.18 - }
1.19 + }
1.20 +
1.21 + private static string[] GetRegistryPortNames() {
1.22 + List<string> result = new List<string>();
1.23 + try {
1.24 + RegistryKey key = Registry.LocalMachine.OpenSubKey(
1.25 + @"SYSTEM\CurrentControlSet\Enum\USB\Vid_10c4&Pid_ea60&Mi_00");
1.26 + if (key != null) {
1.27 + foreach (string subKeyName in key.GetSubKeyNames()) {
1.28 + RegistryKey subKey =
1.29 + key.OpenSubKey(subKeyName + "\\" + "Device Parameters");
1.30 + if (subKey != null) {
1.31 + string name = subKey.GetValue("PortName") as string;
1.32 + if (name != null)
1.33 + result.Add((string)name);
1.34 + }
1.35 + }
1.36 + }
1.37 + } catch (SecurityException) { }
1.38 + return result.ToArray();
1.39 + }
1.40
1.41 public HeatmasterGroup(ISettings settings) {
1.42 +
1.43 + // No implementation for Heatmaster on Unix systems
1.44 + int p = (int)System.Environment.OSVersion.Platform;
1.45 + if ((p == 4) || (p == 128))
1.46 + return;
1.47
1.48 - string[] portNames = SerialPort.GetPortNames();
1.49 + string[] portNames = GetRegistryPortNames();
1.50 for (int i = portNames.Length - 1; i >= 0; i--) {
1.51 try {
1.52
1.53 @@ -85,50 +112,46 @@
1.54 }
1.55
1.56 if (serialPort.IsOpen) {
1.57 - if (serialPort.CtsHolding) {
1.58 - serialPort.DiscardInBuffer();
1.59 - serialPort.DiscardOutBuffer();
1.60 - serialPort.Write(new byte[] { 0xAA }, 0, 1);
1.61 + serialPort.DiscardInBuffer();
1.62 + serialPort.DiscardOutBuffer();
1.63 + serialPort.Write(new byte[] { 0xAA }, 0, 1);
1.64
1.65 - int j = 0;
1.66 - while (serialPort.BytesToRead == 0 && j < 10) {
1.67 - Thread.Sleep(20);
1.68 - j++;
1.69 + int j = 0;
1.70 + while (serialPort.BytesToRead == 0 && j < 10) {
1.71 + Thread.Sleep(20);
1.72 + j++;
1.73 + }
1.74 + if (serialPort.BytesToRead > 0) {
1.75 + bool flag = false;
1.76 + while (serialPort.BytesToRead > 0 && !flag) {
1.77 + flag |= (serialPort.ReadByte() == 0xAA);
1.78 }
1.79 - if (serialPort.BytesToRead > 0) {
1.80 - bool flag = false;
1.81 - while (serialPort.BytesToRead > 0 && !flag) {
1.82 - flag |= (serialPort.ReadByte() == 0xAA);
1.83 - }
1.84 - if (flag) {
1.85 - serialPort.WriteLine("[0:0]RH");
1.86 - try {
1.87 - int k = 0;
1.88 - int revision = 0;
1.89 - while (k < 5) {
1.90 - string line = ReadLine(serialPort, 100);
1.91 - if (line.StartsWith("-[0:0]RH:")) {
1.92 - int.TryParse(line.Substring(9), out revision);
1.93 - break;
1.94 - }
1.95 - k++;
1.96 + if (flag) {
1.97 + serialPort.WriteLine("[0:0]RH");
1.98 + try {
1.99 + int k = 0;
1.100 + int revision = 0;
1.101 + while (k < 5) {
1.102 + string line = ReadLine(serialPort, 100);
1.103 + if (line.StartsWith("-[0:0]RH:")) {
1.104 + int.TryParse(line.Substring(9), out revision);
1.105 + break;
1.106 }
1.107 - isValid = (revision == 770);
1.108 - if (!isValid) {
1.109 - report.Append("Status: Wrong Hardware Revision " +
1.110 - revision.ToString());
1.111 - }
1.112 - } catch (TimeoutException) {
1.113 - report.AppendLine("Status: Timeout Reading Revision");
1.114 + k++;
1.115 }
1.116 - } else {
1.117 - report.AppendLine("Status: Wrong Startflag");
1.118 + isValid = (revision == 770);
1.119 + if (!isValid) {
1.120 + report.Append("Status: Wrong Hardware Revision " +
1.121 + revision.ToString());
1.122 + }
1.123 + } catch (TimeoutException) {
1.124 + report.AppendLine("Status: Timeout Reading Revision");
1.125 }
1.126 } else {
1.127 - report.AppendLine("Status: No Response");
1.128 + report.AppendLine("Status: Wrong Startflag");
1.129 }
1.130 } else {
1.131 - report.AppendLine("Status: Not Clear to Send");
1.132 + report.AppendLine("Status: No Response");
1.133 }
1.134 serialPort.DiscardInBuffer();
1.135 serialPort.Close();