Fixed a few problems with the Heatmaster.
1.1 --- a/Hardware/Heatmaster/Heatmaster.cs Sun Aug 22 21:53:11 2010 +0000
1.2 +++ b/Hardware/Heatmaster/Heatmaster.cs Mon Aug 23 20:00:06 2010 +0000
1.3 @@ -61,6 +61,8 @@
1.4
1.5 private bool available = false;
1.6
1.7 + private StringBuilder buffer = new StringBuilder();
1.8 +
1.9 private string ReadLine(int timeout) {
1.10 int i = 0;
1.11 StringBuilder builder = new StringBuilder();
1.12 @@ -82,7 +84,7 @@
1.13 private string ReadField(int device, char field) {
1.14 serialPort.WriteLine("[0:" + device + "]R" + field);
1.15 for (int i = 0; i < 5; i++) {
1.16 - string s = ReadLine(100);
1.17 + string s = ReadLine(200);
1.18 Match match = Regex.Match(s, @"-\[0:" + device.ToString() + @"\]R" +
1.19 Regex.Escape(field.ToString()) + ":(.*)");
1.20 if (match.Success)
1.21 @@ -111,7 +113,7 @@
1.22 private bool WriteField(int device, char field, string value) {
1.23 serialPort.WriteLine("[0:" + device + "]W" + field + ":" + value);
1.24 for (int i = 0; i < 5; i++) {
1.25 - string s = ReadLine(100);
1.26 + string s = ReadLine(200);
1.27 Match match = Regex.Match(s, @"-\[0:" + device.ToString() + @"\]W" +
1.28 Regex.Escape(field.ToString()) + ":" + value);
1.29 if (match.Success)
1.30 @@ -222,42 +224,52 @@
1.31 get { return "Heatmaster"; }
1.32 }
1.33
1.34 + private void ProcessUpdateLine(string line) {
1.35 + Match match = Regex.Match(line, @">\[0:(\d+)\]([0-9:\|-]+)");
1.36 + if (match.Success) {
1.37 + int device;
1.38 + if (int.TryParse(match.Groups[1].Value, out device)) {
1.39 + foreach (string s in match.Groups[2].Value.Split('|')) {
1.40 + string[] strings = s.Split(':');
1.41 + int[] ints = new int[strings.Length];
1.42 + for (int i = 0; i < ints.Length; i++)
1.43 + ints[i] = int.Parse(strings[i]);
1.44 + switch (device) {
1.45 + case 32:
1.46 + if (ints.Length == 3 && ints[0] <= fans.Length) {
1.47 + fans[ints[0] - 1].Value = ints[1];
1.48 + controls[ints[0] - 1].Value = (100 / 255.0f) * ints[2];
1.49 + }
1.50 + break;
1.51 + case 48:
1.52 + if (ints.Length == 2 && ints[0] <= temperatures.Length)
1.53 + temperatures[ints[0] - 1].Value = 0.1f * ints[1];
1.54 + break;
1.55 + case 64:
1.56 + if (ints.Length == 3 && ints[0] <= flows.Length)
1.57 + flows[ints[0] - 1].Value = 0.1f * ints[1];
1.58 + break;
1.59 + case 80:
1.60 + if (ints.Length == 2 && ints[0] <= relays.Length)
1.61 + relays[ints[0] - 1].Value = 100 * ints[1];
1.62 + break;
1.63 + }
1.64 + }
1.65 + }
1.66 + }
1.67 + }
1.68 +
1.69 public override void Update() {
1.70 if (!available)
1.71 return;
1.72
1.73 while (serialPort.BytesToRead > 0) {
1.74 - Match match = Regex.Match(ReadLine(0), @">\[0:(\d+)\]([0-9:\|-]+)");
1.75 - if (match.Success) {
1.76 - int device;
1.77 - if (int.TryParse(match.Groups[1].Value, out device)) {
1.78 - foreach (string s in match.Groups[2].Value.Split('|')) {
1.79 - string[] strings = s.Split(':');
1.80 - int[] ints = new int[strings.Length];
1.81 - for (int i = 0; i < ints.Length; i++)
1.82 - ints[i] = int.Parse(strings[i]);
1.83 - switch (device) {
1.84 - case 32:
1.85 - if (ints.Length == 3 && ints[0] <= fans.Length) {
1.86 - fans[ints[0] - 1].Value = ints[1];
1.87 - controls[ints[0] - 1].Value = (100 / 255.0f) * ints[2];
1.88 - }
1.89 - break;
1.90 - case 48:
1.91 - if (ints.Length == 2 && ints[0] <= temperatures.Length)
1.92 - temperatures[ints[0] - 1].Value = 0.1f * ints[1];
1.93 - break;
1.94 - case 64:
1.95 - if (ints.Length == 3 && ints[0] <= flows.Length)
1.96 - flows[ints[0] - 1].Value = 0.1f * ints[1];
1.97 - break;
1.98 - case 80:
1.99 - if (ints.Length == 2 && ints[0] <= relays.Length)
1.100 - relays[ints[0] - 1].Value = 100 * ints[1];
1.101 - break;
1.102 - }
1.103 - }
1.104 - }
1.105 + byte b = (byte)serialPort.ReadByte();
1.106 + if (b == 0x0D) {
1.107 + ProcessUpdateLine(buffer.ToString());
1.108 + buffer.Length = 0;
1.109 + } else {
1.110 + buffer.Append((char)b);
1.111 }
1.112 }
1.113 }
2.1 --- a/Hardware/Heatmaster/HeatmasterGroup.cs Sun Aug 22 21:53:11 2010 +0000
2.2 +++ b/Hardware/Heatmaster/HeatmasterGroup.cs Mon Aug 23 20:00:06 2010 +0000
2.3 @@ -38,8 +38,10 @@
2.4 using System;
2.5 using System.Collections.Generic;
2.6 using System.IO.Ports;
2.7 +using System.Security;
2.8 using System.Text;
2.9 using System.Threading;
2.10 +using Microsoft.Win32;
2.11
2.12 namespace OpenHardwareMonitor.Hardware.Heatmaster {
2.13 internal class HeatmasterGroup : IGroup {
2.14 @@ -63,11 +65,36 @@
2.15 Thread.Sleep(1);
2.16 }
2.17 throw new TimeoutException();
2.18 - }
2.19 + }
2.20 +
2.21 + private static string[] GetRegistryPortNames() {
2.22 + List<string> result = new List<string>();
2.23 + try {
2.24 + RegistryKey key = Registry.LocalMachine.OpenSubKey(
2.25 + @"SYSTEM\CurrentControlSet\Enum\USB\Vid_10c4&Pid_ea60&Mi_00");
2.26 + if (key != null) {
2.27 + foreach (string subKeyName in key.GetSubKeyNames()) {
2.28 + RegistryKey subKey =
2.29 + key.OpenSubKey(subKeyName + "\\" + "Device Parameters");
2.30 + if (subKey != null) {
2.31 + string name = subKey.GetValue("PortName") as string;
2.32 + if (name != null)
2.33 + result.Add((string)name);
2.34 + }
2.35 + }
2.36 + }
2.37 + } catch (SecurityException) { }
2.38 + return result.ToArray();
2.39 + }
2.40
2.41 public HeatmasterGroup(ISettings settings) {
2.42 +
2.43 + // No implementation for Heatmaster on Unix systems
2.44 + int p = (int)System.Environment.OSVersion.Platform;
2.45 + if ((p == 4) || (p == 128))
2.46 + return;
2.47
2.48 - string[] portNames = SerialPort.GetPortNames();
2.49 + string[] portNames = GetRegistryPortNames();
2.50 for (int i = portNames.Length - 1; i >= 0; i--) {
2.51 try {
2.52
2.53 @@ -85,50 +112,46 @@
2.54 }
2.55
2.56 if (serialPort.IsOpen) {
2.57 - if (serialPort.CtsHolding) {
2.58 - serialPort.DiscardInBuffer();
2.59 - serialPort.DiscardOutBuffer();
2.60 - serialPort.Write(new byte[] { 0xAA }, 0, 1);
2.61 + serialPort.DiscardInBuffer();
2.62 + serialPort.DiscardOutBuffer();
2.63 + serialPort.Write(new byte[] { 0xAA }, 0, 1);
2.64
2.65 - int j = 0;
2.66 - while (serialPort.BytesToRead == 0 && j < 10) {
2.67 - Thread.Sleep(20);
2.68 - j++;
2.69 + int j = 0;
2.70 + while (serialPort.BytesToRead == 0 && j < 10) {
2.71 + Thread.Sleep(20);
2.72 + j++;
2.73 + }
2.74 + if (serialPort.BytesToRead > 0) {
2.75 + bool flag = false;
2.76 + while (serialPort.BytesToRead > 0 && !flag) {
2.77 + flag |= (serialPort.ReadByte() == 0xAA);
2.78 }
2.79 - if (serialPort.BytesToRead > 0) {
2.80 - bool flag = false;
2.81 - while (serialPort.BytesToRead > 0 && !flag) {
2.82 - flag |= (serialPort.ReadByte() == 0xAA);
2.83 - }
2.84 - if (flag) {
2.85 - serialPort.WriteLine("[0:0]RH");
2.86 - try {
2.87 - int k = 0;
2.88 - int revision = 0;
2.89 - while (k < 5) {
2.90 - string line = ReadLine(serialPort, 100);
2.91 - if (line.StartsWith("-[0:0]RH:")) {
2.92 - int.TryParse(line.Substring(9), out revision);
2.93 - break;
2.94 - }
2.95 - k++;
2.96 + if (flag) {
2.97 + serialPort.WriteLine("[0:0]RH");
2.98 + try {
2.99 + int k = 0;
2.100 + int revision = 0;
2.101 + while (k < 5) {
2.102 + string line = ReadLine(serialPort, 100);
2.103 + if (line.StartsWith("-[0:0]RH:")) {
2.104 + int.TryParse(line.Substring(9), out revision);
2.105 + break;
2.106 }
2.107 - isValid = (revision == 770);
2.108 - if (!isValid) {
2.109 - report.Append("Status: Wrong Hardware Revision " +
2.110 - revision.ToString());
2.111 - }
2.112 - } catch (TimeoutException) {
2.113 - report.AppendLine("Status: Timeout Reading Revision");
2.114 + k++;
2.115 }
2.116 - } else {
2.117 - report.AppendLine("Status: Wrong Startflag");
2.118 + isValid = (revision == 770);
2.119 + if (!isValid) {
2.120 + report.Append("Status: Wrong Hardware Revision " +
2.121 + revision.ToString());
2.122 + }
2.123 + } catch (TimeoutException) {
2.124 + report.AppendLine("Status: Timeout Reading Revision");
2.125 }
2.126 } else {
2.127 - report.AppendLine("Status: No Response");
2.128 + report.AppendLine("Status: Wrong Startflag");
2.129 }
2.130 } else {
2.131 - report.AppendLine("Status: Not Clear to Send");
2.132 + report.AppendLine("Status: No Response");
2.133 }
2.134 serialPort.DiscardInBuffer();
2.135 serialPort.Close();
3.1 --- a/Properties/AssemblyVersion.cs Sun Aug 22 21:53:11 2010 +0000
3.2 +++ b/Properties/AssemblyVersion.cs Mon Aug 23 20:00:06 2010 +0000
3.3 @@ -38,5 +38,5 @@
3.4 using System;
3.5 using System.Reflection;
3.6
3.7 -[assembly: AssemblyVersion("0.1.37.4")]
3.8 -[assembly: AssemblyFileVersion("0.1.37.4")]
3.9 +[assembly: AssemblyVersion("0.1.37.7")]
3.10 +[assembly: AssemblyFileVersion("0.1.37.7")]