Fixed some hardware sorting issue in the gadget. Hardware with the same type and name would be added to the same section.
3 Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 The contents of this file are subject to the Mozilla Public License Version
6 1.1 (the "License"); you may not use this file except in compliance with
7 the License. You may obtain a copy of the License at
9 http://www.mozilla.org/MPL/
11 Software distributed under the License is distributed on an "AS IS" basis,
12 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 for the specific language governing rights and limitations under the License.
15 The Original Code is the Open Hardware Monitor code.
17 The Initial Developer of the Original Code is
18 Michael Möller <m.moeller@gmx.ch>.
19 Portions created by the Initial Developer are Copyright (C) 2009-2010
20 the Initial Developer. All Rights Reserved.
24 Alternatively, the contents of this file may be used under the terms of
25 either the GNU General Public License Version 2 or later (the "GPL"), or
26 the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 in which case the provisions of the GPL or the LGPL are applicable instead
28 of those above. If you wish to allow use of your version of this file only
29 under the terms of either the GPL or the LGPL, and not to allow others to
30 use your version of this file under the terms of the MPL, indicate your
31 decision by deleting the provisions above and replace them with the notice
32 and other provisions required by the GPL or the LGPL. If you do not delete
33 the provisions above, a recipient may use your version of this file under
34 the terms of any one of the MPL, the GPL or the LGPL.
39 using System.Collections.Generic;
40 using System.Globalization;
42 using System.Threading;
44 namespace OpenHardwareMonitor.Hardware.TBalancer {
45 internal class TBalancerGroup : IGroup {
47 private List<TBalancer> hardware = new List<TBalancer>();
48 private StringBuilder report = new StringBuilder();
50 public TBalancerGroup(ISettings settings) {
54 FTD2XX.FT_CreateDeviceInfoList(out numDevices);
55 } catch (DllNotFoundException) { return; }
56 catch (ArgumentNullException) { return; }
57 catch (EntryPointNotFoundException) { return; }
58 catch (BadImageFormatException) { return; }
60 FT_DEVICE_INFO_NODE[] info = new FT_DEVICE_INFO_NODE[numDevices];
61 FTD2XX.FT_GetDeviceInfoList(info, ref numDevices);
63 for (int i = 0; i < numDevices; i++) {
64 report.Append("Device Index: ");
65 report.AppendLine(i.ToString(CultureInfo.InvariantCulture));
69 status = FTD2XX.FT_Open(i, out handle);
70 if (status != FT_STATUS.FT_OK) {
71 report.AppendLine("Open Status: " + status);
75 FTD2XX.FT_SetBaudRate(handle, 19200);
76 FTD2XX.FT_SetDataCharacteristics(handle, 8, 1, 0);
77 FTD2XX.FT_SetFlowControl(handle, FT_FLOW_CONTROL.FT_FLOW_RTS_CTS, 0x11,
79 FTD2XX.FT_SetTimeouts(handle, 1000, 1000);
80 FTD2XX.FT_Purge(handle, FT_PURGE.FT_PURGE_ALL);
82 status = FTD2XX.Write(handle, new byte[] { 0x38 });
83 if (status != FT_STATUS.FT_OK) {
84 report.AppendLine("Write Status: " + status);
85 FTD2XX.FT_Close(handle);
90 byte protocolVersion = 0;
93 while (FTD2XX.BytesToRead(handle) == 0 && j < 2) {
97 if (FTD2XX.BytesToRead(handle) > 0) {
98 if (FTD2XX.ReadByte(handle) == TBalancer.STARTFLAG) {
99 while (FTD2XX.BytesToRead(handle) < 284 && j < 5) {
103 int length = FTD2XX.BytesToRead(handle);
105 byte[] data = new byte[285];
106 data[0] = TBalancer.STARTFLAG;
107 for (int k = 1; k < data.Length; k++)
108 data[k] = FTD2XX.ReadByte(handle);
110 // check protocol version 2X (protocols seen: 2C, 2A, 28)
111 isValid = (data[274] & 0xF0) == 0x20;
112 protocolVersion = data[274];
114 report.Append("Status: Wrong Protocol Version: 0x");
116 protocolVersion.ToString("X", CultureInfo.InvariantCulture));
119 report.AppendLine("Status: Wrong Message Length: " + length);
122 report.AppendLine("Status: Wrong Startflag");
125 report.AppendLine("Status: No Response");
128 FTD2XX.FT_Purge(handle, FT_PURGE.FT_PURGE_ALL);
129 FTD2XX.FT_Close(handle);
132 report.AppendLine("Status: OK");
133 hardware.Add(new TBalancer(i, protocolVersion, settings));
140 public IHardware[] Hardware {
142 return hardware.ToArray();
146 public string GetReport() {
147 if (report.Length > 0) {
148 report.Insert(0, "FTD2XX" + Environment.NewLine +
149 Environment.NewLine);
151 return report.ToString();
156 public void Close() {
157 foreach (TBalancer tbalancer in hardware)