Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
0
        private void GetPowerUsage()
        {
            string SensorType;
            float? SensorValue;

            for (int i = 0; i < computer.Hardware.Count(); i++)
            {
                for (int j = 0; j < computer.Hardware[i].Sensors.Count(); j++)
                {
                    SensorType  = computer.Hardware[i].Sensors[j].SensorType.ToString();
                    SensorValue = computer.Hardware[i].Sensors[j].Value;

                    if (SensorType == "Power")
                    {
                        PowerUsage.Add(SensorValue);
                    }
                }
            }

            computer.Close();
            return;
        }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
0
Arquivo: OHW.cs Projeto: mkahvi/sysmon
        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?
            }
        }