Пример #1
0
 private void InitHardware()
 {
     computer            = new OpenHardwareMonitor.Hardware.Computer();
     computer.CPUEnabled = true;
     computer.Open();
     return;
 }
Пример #2
0
        private void Thread_HardwareMonitor()
        {
            try
            {
                while (true)
                {
                    System.Threading.Thread.Sleep(500);

                    OpenHardwareMonitor.Hardware.Computer lComputerHardware = new OpenHardwareMonitor.Hardware.Computer();
                    lComputerHardware.MainboardEnabled     = false;
                    lComputerHardware.FanControllerEnabled = false;
                    lComputerHardware.CPUEnabled           = false;
                    lComputerHardware.GPUEnabled           = true;
                    lComputerHardware.RAMEnabled           = false;
                    lComputerHardware.HDDEnabled           = false;
                    lComputerHardware.Open();

                    this.UpdateSensor(lComputerHardware);

                    lComputerHardware.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message.ToString(), "Error : Thread_HardwareMonitor", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Environment.Exit(0);
            }
        }
Пример #3
0
        private void GatherOSInfo(Context context)
        {
            var ohw = new OpenHardwareMonitor.Hardware.Computer();

            ohw.CPUEnabled = ohw.GPUEnabled = ohw.HDDEnabled = ohw.MainboardEnabled = ohw.RAMEnabled = true;
            ohw.Open();
            context.Response.Content["info.system"] = new SystemInfo()
            {
                OS = Environment.OSVersion.VersionString,
                HW = ohw.Hardware.Select(x => new HardwareInfo()
                {
                    Type = x.HardwareType.ToString(),
                    Name = x.Name
                }).ToArray()
            };
        }
Пример #4
0
 private void StartTelemetry()
 {
     try
     {
         thisComputer.CPUEnabled       = true;
         thisComputer.GPUEnabled       = true;
         thisComputer.HDDEnabled       = true;
         thisComputer.MainboardEnabled = true;
         thisComputer.RAMEnabled       = true;
         thisComputer.Open();
     }
     catch (Exception)
     {
         throw;
     }
 }
Пример #5
0
        private void FrmMain_Load(object sender, EventArgs e)
        {
            Control.CheckForIllegalCrossThreadCalls = false;
            this.pal_Monitor.Controls.Clear();

            try
            {
                string ltype      = string.Empty;
                int    lGPU_Count = 0;

                OpenHardwareMonitor.Hardware.Computer lComputerHardware = new OpenHardwareMonitor.Hardware.Computer();
                lComputerHardware.MainboardEnabled     = false;
                lComputerHardware.FanControllerEnabled = false;
                lComputerHardware.CPUEnabled           = false;
                lComputerHardware.GPUEnabled           = true;
                lComputerHardware.RAMEnabled           = false;
                lComputerHardware.HDDEnabled           = false;
                lComputerHardware.Open();

                for (int bInxHardWare = 0; bInxHardWare < lComputerHardware.Hardware.Count(); bInxHardWare++)
                {
                    ltype = lComputerHardware.Hardware[bInxHardWare].HardwareType.ToString();

                    if ((!string.IsNullOrEmpty(ltype)) && (ltype.ToUpper().Substring(0, 3) == "GPU"))
                    {
                        lGPU_Count++;
                    }
                }

                this.ReSize_Monitor(lGPU_Count);
                this.BuildLabel(lGPU_Count);
                this.UpdateSensor(lComputerHardware);
                this.UpdateMinMax(0);

                lComputerHardware.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message.ToString(), "Error : FrmMain_Load", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Environment.Exit(0);
            }
        }
Пример #6
0
        private void BindHardwareSensors()
        {
            OpenHardwareMonitor.Hardware.Computer computer = new OpenHardwareMonitor.Hardware.Computer();
            computer.CPUEnabled           = true;
            computer.RAMEnabled           = true;
            computer.MainboardEnabled     = true;
            computer.FanControllerEnabled = true;
            computer.HDDEnabled           = true;
            computer.Open();

            Table table = new Table();

            table.CellPadding = 0;
            table.CellSpacing = 0;

            TableRow tableRowHeadline = new TableRow();

            tableRowHeadline.CssClass = "HardwareSensorsHeadline";

            TableCell tableCellTitleHeadline = new TableCell();

            tableCellTitleHeadline.Text = "Sensor";

            TableCell tableCellLoadHeadline = new TableCell();

            tableCellLoadHeadline.Text = "Load";

            TableCell tableCellTempHeadline = new TableCell();

            tableCellTempHeadline.Text = "Temp";

            tableRowHeadline.Cells.Add(tableCellTitleHeadline);
            tableRowHeadline.Cells.Add(tableCellLoadHeadline);
            tableRowHeadline.Cells.Add(tableCellTempHeadline);

            table.Rows.Add(tableRowHeadline);

            foreach (OpenHardwareMonitor.Hardware.IHardware hardware in computer.Hardware)
            {
                if (hardware.HardwareType != OpenHardwareMonitor.Hardware.HardwareType.CPU)
                {
                    continue;
                }

                Dictionary <string, int[]> cores = new Dictionary <string, int[]>();

                foreach (OpenHardwareMonitor.Hardware.ISensor sensor in hardware.Sensors)
                {
                    if (!cores.ContainsKey(sensor.Name))
                    {
                        cores.Add(sensor.Name, new int[2]);
                    }

                    if (sensor.SensorType == OpenHardwareMonitor.Hardware.SensorType.Load)
                    {
                        try
                        {
                            cores[sensor.Name][0] = (int)sensor.Value.Value;
                        }
                        catch { }
                    }
                    else if (sensor.SensorType == OpenHardwareMonitor.Hardware.SensorType.Temperature)
                    {
                        try
                        {
                            cores[sensor.Name][1] = (int)sensor.Value.Value;

                            foreach (OpenHardwareMonitor.Hardware.SensorValue v in sensor.Values)
                            {
                                cores[sensor.Name][1] = (int)v.Value;
                            }
                        }
                        catch { }
                    }
                }

                foreach (string core in cores.Keys)
                {
                    TableRow tableRow = new TableRow();

                    TableCell tableCellTitle = new TableCell();
                    tableCellTitle.Text = core;

                    TableCell tableCellLoad = new TableCell();
                    tableCellLoad.Text = cores[core][0].ToString() + "%";

                    TableCell tableCellTemp = new TableCell();
                    tableCellTemp.Text = cores[core][1] != 0 ? cores[core][1].ToString() + "°" : "N/A";

                    tableRow.Cells.Add(tableCellTitle);
                    tableRow.Cells.Add(tableCellLoad);
                    tableRow.Cells.Add(tableCellTemp);

                    table.Rows.Add(tableRow);
                }
            }

            foreach (OpenHardwareMonitor.Hardware.IHardware hardware in computer.Hardware)
            {
                if (hardware.HardwareType == OpenHardwareMonitor.Hardware.HardwareType.CPU)
                {
                    continue;
                }

                Dictionary <string, int[]> cores = new Dictionary <string, int[]>();

                foreach (OpenHardwareMonitor.Hardware.ISensor sensor in hardware.Sensors)
                {
                    TableRow tableRow = new TableRow();

                    TableCell tableCellTitle = new TableCell();
                    tableCellTitle.Text = hardware.Name + " - " + sensor.Name;

                    TableCell tableCellLoad = new TableCell();
                    tableCellLoad.Text = sensor.Value != null?sensor.Value.ToString() : "N/A";

                    tableRow.Cells.Add(tableCellTitle);
                    tableRow.Cells.Add(tableCellLoad);

                    table.Rows.Add(tableRow);
                }
            }

            pnlHardwareSensors.Controls.Add(table);

            computer.Close();
        }
Пример #7
0
        private static void RefreshTemps()
        {
            //- Variables
            warn  = false;
            temps = new Dictionary <string, double>();

            //- Load Open Hardware Monitor library
            try
            {
                pcHW = new OpenHardwareMonitor.Hardware.Computer()
                {
                    CPUEnabled = true,
                    GPUEnabled = true,
                    HDDEnabled = true,
                };
                pcHW.Open();
            }
            catch { }

            try
            {
                for (int h = 0; h < pcHW.Hardware.Length; h++)
                {
                    var hw = pcHW.Hardware[h];
                    if (hw.HardwareType == OpenHardwareMonitor.Hardware.HardwareType.CPU)
                    {
                        hw.Update();
                        Thread.Sleep(1000);
                        hw.Update();
                        Thread.Sleep(1000);
                        hw.Update();

                        for (int s = 0; s < hw.Sensors.Length; s++)
                        {
                            var sensor = hw.Sensors[s];
                            if (sensor.SensorType == OpenHardwareMonitor.Hardware.SensorType.Temperature)
                            {
                                if (sensor.Value != null)
                                {
                                    //- Get temperature value and convert that to F
                                    double val = (double)sensor.Value;
                                    val = Math.Round((val * 1.8) + 32, 0);

                                    temps.Add("CPU", val);
                                }
                            }
                        }
                    }
                    else if (hw.HardwareType == OpenHardwareMonitor.Hardware.HardwareType.GpuAti ||
                             hw.HardwareType == OpenHardwareMonitor.Hardware.HardwareType.GpuNvidia)
                    {
                        hw.Update();
                        for (int s = 0; s < hw.Sensors.Length; s++)
                        {
                            var sensor = hw.Sensors[s];
                            if (sensor.SensorType == OpenHardwareMonitor.Hardware.SensorType.Temperature)
                            {
                                if (sensor.Value != null)
                                {
                                    //- Get temperature value and convert that to F
                                    double val = (double)sensor.Value;
                                    val = Math.Round((val * 1.8) + 32, 0);

                                    temps.Add("GPU", val);
                                }
                            }
                        }
                    }
                    else if (hw.HardwareType == OpenHardwareMonitor.Hardware.HardwareType.HDD)
                    {
                        hw.Update();

                        for (int s = 0; s < hw.Sensors.Length; s++)
                        {
                            var sensor = hw.Sensors[s];
                            if (sensor.SensorType == OpenHardwareMonitor.Hardware.SensorType.Temperature)
                            {
                                if (sensor.Value != null)
                                {
                                    //- Get temperature value and convert that to F
                                    double val = (double)sensor.Value;
                                    val = Math.Round((val * 1.8) + 32, 0);

                                    temps.Add("HDD", val);
                                }
                            }
                        }
                    }
                    else if (hw.HardwareType == OpenHardwareMonitor.Hardware.HardwareType.Mainboard)
                    {
                        hw.Update();

                        for (int s = 0; s < hw.Sensors.Length; s++)
                        {
                            var sensor = hw.Sensors[s];
                            if (sensor.SensorType == OpenHardwareMonitor.Hardware.SensorType.Temperature)
                            {
                                if (sensor.Value != null)
                                {
                                    //- Get temperature value and convert that to F
                                    double val = (double)sensor.Value;
                                    val = Math.Round((val * 1.8) + 32, 0);

                                    temps.Add("Mobo", val);
                                }
                            }
                        }
                    }
                    else if (hw.HardwareType == OpenHardwareMonitor.Hardware.HardwareType.RAM)
                    {
                        hw.Update();

                        for (int s = 0; s < hw.Sensors.Length; s++)
                        {
                            var sensor = hw.Sensors[s];
                            if (sensor.SensorType == OpenHardwareMonitor.Hardware.SensorType.Temperature)
                            {
                                if (sensor.Value != null)
                                {
                                    //- Get temperature value and convert that to F
                                    double val = (double)sensor.Value;
                                    val = Math.Round((val * 1.8) + 32, 0);

                                    temps.Add("RAM", val);
                                }
                            }
                        }
                    }
                    else if (hw.HardwareType == OpenHardwareMonitor.Hardware.HardwareType.Heatmaster)
                    {
                        hw.Update();

                        for (int s = 0; s < hw.Sensors.Length; s++)
                        {
                            var sensor = hw.Sensors[s];
                            if (sensor.SensorType == OpenHardwareMonitor.Hardware.SensorType.Temperature)
                            {
                                if (sensor.Value != null)
                                {
                                    //- Get temperature value and convert that to F
                                    double val = (double)sensor.Value;
                                    val = Math.Round((val * 1.8) + 32, 0);

                                    temps.Add("Heatsink", val);
                                }
                            }
                        }
                    }
                }
            }
            catch { failed = true; }
        }
Пример #8
0
        public OHW()
        {
            OpenHardwareMonitor.Hardware.Computer computer;

            computer = new OpenHardwareMonitor.Hardware.Computer()
            {
                GPUEnabled = true,
                CPUEnabled = true,
                //MainboardEnabled = true, // doesn't seem to have anything
                FanControllerEnabled = true,
            };

            computer.Open();
            if (computer.Hardware.Length == 0)
            {
                computer.Close();
                throw new Exception("OHM failed to initialize.");
            }

            try
            {
                foreach (var hw in computer.Hardware)
                {
                    hw.Update();

                    /*
                     * foreach (var shw in hw.SubHardware)
                     *      shw.Update();
                     */

                    /*
                     *
                     * CPU Core #1 : Load = 60.00
                     * CPU Core #2 : Load = 40.00
                     * CPU Total : Load = 50.00
                     * CPU Core #1 : Clock = 3,411.70
                     * CPU Core #2 : Clock = 3,411.70
                     *
                     * GPU Core : Temperature = 42.00
                     * GPU : Fan = 1,110.00
                     * GPU Core : Clock = 796.94
                     * GPU Memory : Clock = 3,004.68
                     * GPU Shader : Clock = 1,593.87
                     * GPU Core : Load = 3.00
                     * GPU Memory Controller : Load = 2.00
                     * GPU Video Engine : Load = 0.00 // this is "always" zero, useless stat
                     * GPU Fan : Control = 32.00
                     * GPU Memory Total : SmallData = 2,048.00
                     * GPU Memory Used : SmallData = 1,301.16
                     * GPU Memory Free : SmallData = 746.84
                     * GPU Memory : Load = 63.53
                     */

                    Console.WriteLine("Hardware: " + hw.Name + $" ({hw.HardwareType.ToString()})");

                    switch (hw.HardwareType)
                    {
                    case OpenHardwareMonitor.Hardware.HardwareType.CPU:
                        // only load and clock sensors normally
                        // temperature sensor requires admin rights
                        foreach (var sensor in hw.Sensors)
                        {
                            if (sensor.SensorType == OpenHardwareMonitor.Hardware.SensorType.Temperature)
                            {
                                cpuTemp = sensor;
                            }
                        }
                        break;

                    case OpenHardwareMonitor.Hardware.HardwareType.GpuAti:
                    case OpenHardwareMonitor.Hardware.HardwareType.GpuNvidia:
                        GPUName = hw.Name;
                        gpu     = hw;
                        foreach (var sensor in hw.Sensors)
                        {
                            switch (sensor.Name)
                            {
                            default: break;                                             // ignore

                            case "GPU":
                                if (sensor.SensorType == OpenHardwareMonitor.Hardware.SensorType.Fan)
                                {
                                    gpuFan = sensor;
                                }
                                break;

                            case "GPU Core":
                                switch (sensor.SensorType)
                                {
                                case OpenHardwareMonitor.Hardware.SensorType.Temperature:
                                    gpuTmp = sensor;
                                    break;

                                case OpenHardwareMonitor.Hardware.SensorType.Load:
                                    gpuLoad = sensor;
                                    break;

                                case OpenHardwareMonitor.Hardware.SensorType.Clock:
                                    gpuClock = sensor;
                                    break;
                                }
                                break;

                            case "GPU Fan":
                                if (sensor.SensorType == OpenHardwareMonitor.Hardware.SensorType.Control)
                                {
                                    gpuFanControl = sensor;
                                }
                                break;

                            case "GPU Memory":
                                if (sensor.SensorType == OpenHardwareMonitor.Hardware.SensorType.Load)
                                {
                                    gpuMemLoad = sensor;
                                }
                                break;

                            case "GPU Memory Total":
                                if (sensor.SensorType == OpenHardwareMonitor.Hardware.SensorType.SmallData)
                                {
                                    GPUTotalMemory = sensor.Value ?? float.NaN;
                                }
                                break;

                            case "GPU Memory Controller":
                                if (sensor.SensorType == OpenHardwareMonitor.Hardware.SensorType.Load)
                                {
                                    gpuMemCtrl = sensor;
                                }
                                break;
                            }
                        }
                        break;
                    }
                }

                Initialized = true;
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                computer?.Close();                 // not needed?
            }
        }