mirror of
https://github.com/openhardwaremonitor/openhardwaremonitor
synced 2025-08-29 21:37:38 +00:00
Fixed a few problems with the Heatmaster.
This commit is contained in:
parent
4c704e26bb
commit
d66df3de7b
@ -61,6 +61,8 @@ namespace OpenHardwareMonitor.Hardware.Heatmaster {
|
|||||||
|
|
||||||
private bool available = false;
|
private bool available = false;
|
||||||
|
|
||||||
|
private StringBuilder buffer = new StringBuilder();
|
||||||
|
|
||||||
private string ReadLine(int timeout) {
|
private string ReadLine(int timeout) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
@ -82,7 +84,7 @@ namespace OpenHardwareMonitor.Hardware.Heatmaster {
|
|||||||
private string ReadField(int device, char field) {
|
private string ReadField(int device, char field) {
|
||||||
serialPort.WriteLine("[0:" + device + "]R" + field);
|
serialPort.WriteLine("[0:" + device + "]R" + field);
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
string s = ReadLine(100);
|
string s = ReadLine(200);
|
||||||
Match match = Regex.Match(s, @"-\[0:" + device.ToString() + @"\]R" +
|
Match match = Regex.Match(s, @"-\[0:" + device.ToString() + @"\]R" +
|
||||||
Regex.Escape(field.ToString()) + ":(.*)");
|
Regex.Escape(field.ToString()) + ":(.*)");
|
||||||
if (match.Success)
|
if (match.Success)
|
||||||
@ -111,7 +113,7 @@ namespace OpenHardwareMonitor.Hardware.Heatmaster {
|
|||||||
private bool WriteField(int device, char field, string value) {
|
private bool WriteField(int device, char field, string value) {
|
||||||
serialPort.WriteLine("[0:" + device + "]W" + field + ":" + value);
|
serialPort.WriteLine("[0:" + device + "]W" + field + ":" + value);
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
string s = ReadLine(100);
|
string s = ReadLine(200);
|
||||||
Match match = Regex.Match(s, @"-\[0:" + device.ToString() + @"\]W" +
|
Match match = Regex.Match(s, @"-\[0:" + device.ToString() + @"\]W" +
|
||||||
Regex.Escape(field.ToString()) + ":" + value);
|
Regex.Escape(field.ToString()) + ":" + value);
|
||||||
if (match.Success)
|
if (match.Success)
|
||||||
@ -222,42 +224,52 @@ namespace OpenHardwareMonitor.Hardware.Heatmaster {
|
|||||||
get { return "Heatmaster"; }
|
get { return "Heatmaster"; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ProcessUpdateLine(string line) {
|
||||||
|
Match match = Regex.Match(line, @">\[0:(\d+)\]([0-9:\|-]+)");
|
||||||
|
if (match.Success) {
|
||||||
|
int device;
|
||||||
|
if (int.TryParse(match.Groups[1].Value, out device)) {
|
||||||
|
foreach (string s in match.Groups[2].Value.Split('|')) {
|
||||||
|
string[] strings = s.Split(':');
|
||||||
|
int[] ints = new int[strings.Length];
|
||||||
|
for (int i = 0; i < ints.Length; i++)
|
||||||
|
ints[i] = int.Parse(strings[i]);
|
||||||
|
switch (device) {
|
||||||
|
case 32:
|
||||||
|
if (ints.Length == 3 && ints[0] <= fans.Length) {
|
||||||
|
fans[ints[0] - 1].Value = ints[1];
|
||||||
|
controls[ints[0] - 1].Value = (100 / 255.0f) * ints[2];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 48:
|
||||||
|
if (ints.Length == 2 && ints[0] <= temperatures.Length)
|
||||||
|
temperatures[ints[0] - 1].Value = 0.1f * ints[1];
|
||||||
|
break;
|
||||||
|
case 64:
|
||||||
|
if (ints.Length == 3 && ints[0] <= flows.Length)
|
||||||
|
flows[ints[0] - 1].Value = 0.1f * ints[1];
|
||||||
|
break;
|
||||||
|
case 80:
|
||||||
|
if (ints.Length == 2 && ints[0] <= relays.Length)
|
||||||
|
relays[ints[0] - 1].Value = 100 * ints[1];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override void Update() {
|
public override void Update() {
|
||||||
if (!available)
|
if (!available)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
while (serialPort.BytesToRead > 0) {
|
while (serialPort.BytesToRead > 0) {
|
||||||
Match match = Regex.Match(ReadLine(0), @">\[0:(\d+)\]([0-9:\|-]+)");
|
byte b = (byte)serialPort.ReadByte();
|
||||||
if (match.Success) {
|
if (b == 0x0D) {
|
||||||
int device;
|
ProcessUpdateLine(buffer.ToString());
|
||||||
if (int.TryParse(match.Groups[1].Value, out device)) {
|
buffer.Length = 0;
|
||||||
foreach (string s in match.Groups[2].Value.Split('|')) {
|
} else {
|
||||||
string[] strings = s.Split(':');
|
buffer.Append((char)b);
|
||||||
int[] ints = new int[strings.Length];
|
|
||||||
for (int i = 0; i < ints.Length; i++)
|
|
||||||
ints[i] = int.Parse(strings[i]);
|
|
||||||
switch (device) {
|
|
||||||
case 32:
|
|
||||||
if (ints.Length == 3 && ints[0] <= fans.Length) {
|
|
||||||
fans[ints[0] - 1].Value = ints[1];
|
|
||||||
controls[ints[0] - 1].Value = (100 / 255.0f) * ints[2];
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 48:
|
|
||||||
if (ints.Length == 2 && ints[0] <= temperatures.Length)
|
|
||||||
temperatures[ints[0] - 1].Value = 0.1f * ints[1];
|
|
||||||
break;
|
|
||||||
case 64:
|
|
||||||
if (ints.Length == 3 && ints[0] <= flows.Length)
|
|
||||||
flows[ints[0] - 1].Value = 0.1f * ints[1];
|
|
||||||
break;
|
|
||||||
case 80:
|
|
||||||
if (ints.Length == 2 && ints[0] <= relays.Length)
|
|
||||||
relays[ints[0] - 1].Value = 100 * ints[1];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,8 +38,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO.Ports;
|
using System.IO.Ports;
|
||||||
|
using System.Security;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using Microsoft.Win32;
|
||||||
|
|
||||||
namespace OpenHardwareMonitor.Hardware.Heatmaster {
|
namespace OpenHardwareMonitor.Hardware.Heatmaster {
|
||||||
internal class HeatmasterGroup : IGroup {
|
internal class HeatmasterGroup : IGroup {
|
||||||
@ -63,11 +65,36 @@ namespace OpenHardwareMonitor.Hardware.Heatmaster {
|
|||||||
Thread.Sleep(1);
|
Thread.Sleep(1);
|
||||||
}
|
}
|
||||||
throw new TimeoutException();
|
throw new TimeoutException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string[] GetRegistryPortNames() {
|
||||||
|
List<string> result = new List<string>();
|
||||||
|
try {
|
||||||
|
RegistryKey key = Registry.LocalMachine.OpenSubKey(
|
||||||
|
@"SYSTEM\CurrentControlSet\Enum\USB\Vid_10c4&Pid_ea60&Mi_00");
|
||||||
|
if (key != null) {
|
||||||
|
foreach (string subKeyName in key.GetSubKeyNames()) {
|
||||||
|
RegistryKey subKey =
|
||||||
|
key.OpenSubKey(subKeyName + "\\" + "Device Parameters");
|
||||||
|
if (subKey != null) {
|
||||||
|
string name = subKey.GetValue("PortName") as string;
|
||||||
|
if (name != null)
|
||||||
|
result.Add((string)name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SecurityException) { }
|
||||||
|
return result.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
public HeatmasterGroup(ISettings settings) {
|
public HeatmasterGroup(ISettings settings) {
|
||||||
|
|
||||||
|
// No implementation for Heatmaster on Unix systems
|
||||||
|
int p = (int)System.Environment.OSVersion.Platform;
|
||||||
|
if ((p == 4) || (p == 128))
|
||||||
|
return;
|
||||||
|
|
||||||
string[] portNames = SerialPort.GetPortNames();
|
string[] portNames = GetRegistryPortNames();
|
||||||
for (int i = portNames.Length - 1; i >= 0; i--) {
|
for (int i = portNames.Length - 1; i >= 0; i--) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
@ -85,50 +112,46 @@ namespace OpenHardwareMonitor.Hardware.Heatmaster {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (serialPort.IsOpen) {
|
if (serialPort.IsOpen) {
|
||||||
if (serialPort.CtsHolding) {
|
serialPort.DiscardInBuffer();
|
||||||
serialPort.DiscardInBuffer();
|
serialPort.DiscardOutBuffer();
|
||||||
serialPort.DiscardOutBuffer();
|
serialPort.Write(new byte[] { 0xAA }, 0, 1);
|
||||||
serialPort.Write(new byte[] { 0xAA }, 0, 1);
|
|
||||||
|
|
||||||
int j = 0;
|
int j = 0;
|
||||||
while (serialPort.BytesToRead == 0 && j < 10) {
|
while (serialPort.BytesToRead == 0 && j < 10) {
|
||||||
Thread.Sleep(20);
|
Thread.Sleep(20);
|
||||||
j++;
|
j++;
|
||||||
|
}
|
||||||
|
if (serialPort.BytesToRead > 0) {
|
||||||
|
bool flag = false;
|
||||||
|
while (serialPort.BytesToRead > 0 && !flag) {
|
||||||
|
flag |= (serialPort.ReadByte() == 0xAA);
|
||||||
}
|
}
|
||||||
if (serialPort.BytesToRead > 0) {
|
if (flag) {
|
||||||
bool flag = false;
|
serialPort.WriteLine("[0:0]RH");
|
||||||
while (serialPort.BytesToRead > 0 && !flag) {
|
try {
|
||||||
flag |= (serialPort.ReadByte() == 0xAA);
|
int k = 0;
|
||||||
}
|
int revision = 0;
|
||||||
if (flag) {
|
while (k < 5) {
|
||||||
serialPort.WriteLine("[0:0]RH");
|
string line = ReadLine(serialPort, 100);
|
||||||
try {
|
if (line.StartsWith("-[0:0]RH:")) {
|
||||||
int k = 0;
|
int.TryParse(line.Substring(9), out revision);
|
||||||
int revision = 0;
|
break;
|
||||||
while (k < 5) {
|
|
||||||
string line = ReadLine(serialPort, 100);
|
|
||||||
if (line.StartsWith("-[0:0]RH:")) {
|
|
||||||
int.TryParse(line.Substring(9), out revision);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
k++;
|
|
||||||
}
|
}
|
||||||
isValid = (revision == 770);
|
k++;
|
||||||
if (!isValid) {
|
|
||||||
report.Append("Status: Wrong Hardware Revision " +
|
|
||||||
revision.ToString());
|
|
||||||
}
|
|
||||||
} catch (TimeoutException) {
|
|
||||||
report.AppendLine("Status: Timeout Reading Revision");
|
|
||||||
}
|
}
|
||||||
} else {
|
isValid = (revision == 770);
|
||||||
report.AppendLine("Status: Wrong Startflag");
|
if (!isValid) {
|
||||||
|
report.Append("Status: Wrong Hardware Revision " +
|
||||||
|
revision.ToString());
|
||||||
|
}
|
||||||
|
} catch (TimeoutException) {
|
||||||
|
report.AppendLine("Status: Timeout Reading Revision");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
report.AppendLine("Status: No Response");
|
report.AppendLine("Status: Wrong Startflag");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
report.AppendLine("Status: Not Clear to Send");
|
report.AppendLine("Status: No Response");
|
||||||
}
|
}
|
||||||
serialPort.DiscardInBuffer();
|
serialPort.DiscardInBuffer();
|
||||||
serialPort.Close();
|
serialPort.Close();
|
||||||
|
@ -38,5 +38,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
[assembly: AssemblyVersion("0.1.37.4")]
|
[assembly: AssemblyVersion("0.1.37.7")]
|
||||||
[assembly: AssemblyFileVersion("0.1.37.4")]
|
[assembly: AssemblyFileVersion("0.1.37.7")]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user