Hardware/HexStringArray.cs
author moel.mich
Tue, 25 Jun 2013 20:34:29 +0000
changeset 406 3890d78140c2
parent 277 5c80f37c0330
permissions -rw-r--r--
Added support for new Samsung SSDs (like Samsung SSD 840 PRO).
moel@165
     1
/*
moel@165
     2
 
moel@344
     3
  This Source Code Form is subject to the terms of the Mozilla Public
moel@344
     4
  License, v. 2.0. If a copy of the MPL was not distributed with this
moel@344
     5
  file, You can obtain one at http://mozilla.org/MPL/2.0/.
moel@165
     6
 
moel@344
     7
  Copyright (C) 2009-2011 Michael Möller <mmoeller@openhardwaremonitor.org>
moel@344
     8
	
moel@165
     9
*/
moel@165
    10
moel@165
    11
using System;
moel@165
    12
using System.Collections.Generic;
moel@165
    13
moel@165
    14
namespace OpenHardwareMonitor.Hardware {
moel@246
    15
  internal static class HexStringArray {
moel@165
    16
moel@246
    17
    public static byte Read(string s, ushort address) {
moel@246
    18
      string[] lines = s.Split(new[] { '\r', '\n' }, 
moel@246
    19
        StringSplitOptions.RemoveEmptyEntries);
moel@165
    20
moel@246
    21
      foreach (string line in lines) {
moel@277
    22
        string[] array = line.Split(new[] { ' ', '\t' }, 
moel@246
    23
          StringSplitOptions.RemoveEmptyEntries);
moel@272
    24
        if (array.Length == 0)
moel@272
    25
          continue; 
moel@246
    26
        if (Convert.ToInt32(array[0], 16) == (address & 0xFFF0)) 
moel@246
    27
          return Convert.ToByte(array[(address & 0x0F) + 1], 16);
moel@165
    28
      }
moel@165
    29
moel@246
    30
      throw new ArgumentException();
moel@165
    31
    }
moel@165
    32
  }
moel@165
    33
}