Hardware/Heatmaster/Heatmaster.cs
changeset 182 4801e9eaf979
parent 173 fb96c0ca3c2d
child 195 0ee888c485d5
     1.1 --- a/Hardware/Heatmaster/Heatmaster.cs	Tue Sep 07 22:15:02 2010 +0000
     1.2 +++ b/Hardware/Heatmaster/Heatmaster.cs	Wed Sep 08 19:29:58 2010 +0000
     1.3 @@ -36,7 +36,7 @@
     1.4  */
     1.5  
     1.6  using System;
     1.7 -using System.Collections.Generic;
     1.8 +using System.Globalization;
     1.9  using System.IO;
    1.10  using System.IO.Ports;
    1.11  using System.Text;
    1.12 @@ -44,7 +44,7 @@
    1.13  using System.Threading;
    1.14  
    1.15  namespace OpenHardwareMonitor.Hardware.Heatmaster {
    1.16 -  internal class Heatmaster : Hardware {
    1.17 +  internal class Heatmaster : Hardware, IDisposable {
    1.18  
    1.19      private string portName;
    1.20      private SerialPort serialPort;
    1.21 @@ -85,8 +85,9 @@
    1.22        serialPort.WriteLine("[0:" + device + "]R" + field);
    1.23        for (int i = 0; i < 5; i++) {
    1.24          string s = ReadLine(200);
    1.25 -        Match match = Regex.Match(s, @"-\[0:" + device.ToString() + @"\]R" +
    1.26 -          Regex.Escape(field.ToString()) + ":(.*)");
    1.27 +        Match match = Regex.Match(s, @"-\[0:" + 
    1.28 +          device.ToString(CultureInfo.InvariantCulture) + @"\]R" +
    1.29 +          Regex.Escape(field.ToString(CultureInfo.InvariantCulture)) + ":(.*)");
    1.30          if (match.Success) 
    1.31            return match.Groups[1].Value;
    1.32        }
    1.33 @@ -114,8 +115,10 @@
    1.34        serialPort.WriteLine("[0:" + device + "]W" + field + ":" + value);
    1.35        for (int i = 0; i < 5; i++) {
    1.36          string s = ReadLine(200);
    1.37 -        Match match = Regex.Match(s, @"-\[0:" + device.ToString() + @"\]W" + 
    1.38 -          Regex.Escape(field.ToString()) + ":" + value);
    1.39 +        Match match = Regex.Match(s, @"-\[0:" + 
    1.40 +          device.ToString(CultureInfo.InvariantCulture) + @"\]W" + 
    1.41 +          Regex.Escape(field.ToString(CultureInfo.InvariantCulture)) +
    1.42 +          ":" + value);
    1.43          if (match.Success)
    1.44            return true;
    1.45        }
    1.46 @@ -123,7 +126,8 @@
    1.47      }
    1.48  
    1.49      private bool WriteInteger(int device, char field, int value) {
    1.50 -      return WriteField(device, field, value.ToString());
    1.51 +      return WriteField(device, field, 
    1.52 +        value.ToString(CultureInfo.InvariantCulture));
    1.53      }
    1.54  
    1.55      private bool WriteString(int device, char field, string value) {
    1.56 @@ -233,7 +237,7 @@
    1.57              string[] strings = s.Split(':');
    1.58              int[] ints = new int[strings.Length];
    1.59              for (int i = 0; i < ints.Length; i++)
    1.60 -              ints[i] = int.Parse(strings[i]);
    1.61 +              ints[i] = int.Parse(strings[i], CultureInfo.InvariantCulture);
    1.62              switch (device) {
    1.63                case 32:
    1.64                  if (ints.Length == 3 && ints[0] <= fans.Length) {
    1.65 @@ -282,11 +286,11 @@
    1.66        r.Append("Port: ");
    1.67        r.AppendLine(portName);
    1.68        r.Append("Hardware Revision: ");
    1.69 -      r.AppendLine(hardwareRevision.ToString());
    1.70 +      r.AppendLine(hardwareRevision.ToString(CultureInfo.InvariantCulture));
    1.71        r.Append("Firmware Revision: ");
    1.72 -      r.AppendLine(firmwareRevision.ToString());
    1.73 +      r.AppendLine(firmwareRevision.ToString(CultureInfo.InvariantCulture));
    1.74        r.Append("Firmware CRC: ");
    1.75 -      r.AppendLine(firmwareCRC.ToString());
    1.76 +      r.AppendLine(firmwareCRC.ToString(CultureInfo.InvariantCulture));
    1.77        r.AppendLine();
    1.78  
    1.79        return r.ToString();
    1.80 @@ -294,6 +298,15 @@
    1.81  
    1.82      public void Close() {
    1.83        serialPort.Close();
    1.84 +      serialPort.Dispose();
    1.85 +      serialPort = null;
    1.86 +    }
    1.87 +
    1.88 +    public void Dispose() {
    1.89 +      if (serialPort != null) {
    1.90 +        serialPort.Dispose();
    1.91 +        serialPort = null;
    1.92 +      }
    1.93      }
    1.94    }
    1.95  }