LibreHardwareMonitor icon indicating copy to clipboard operation
LibreHardwareMonitor copied to clipboard

not able to read or get sensor data from lpcio in custom tree

Open OminiData opened this issue 2 years ago • 0 comments

iknow this isnt a problem with libremonitor as such because i am able to read lpcio just fine from the librehardware program

but when i am trying to implement it into my own project all iam getting out from the lpcio is fan controll(without any data) but i am not getting voltage, temprature or fans but every other sensors and hardware i am getting out just fine

i am hoping someone can help me with this small issue or atleast guide me on how to get it to work as i am abit lost on how to get it

my readings

Hardware: ASUS ROG MAXIMUS XI FORMULA, Type: Motherboard Subhardware: Nuvoton NCT6798D, Type: SuperIO Sensor: Fan #1, Type: Control, Value: , Min: , Max: Sensor: Fan #2, Type: Control, Value: , Min: , Max: Sensor: Fan #3, Type: Control, Value: , Min: , Max: Sensor: Fan #4, Type: Control, Value: , Min: , Max: Sensor: Fan #5, Type: Control, Value: , Min: , Max: Sensor: Fan #6, Type: Control, Value: , Min: , Max: Sensor: Fan #7, Type: Control, Value: , Min: , Max:

librehardwares reading

+- ASUS ROG MAXIMUS XI FORMULA (/motherboard) | | | +- Nuvoton NCT6798D (/lpc/nct6798d/0) | | +- Vcore : 0.992 0.976 0.992 (/lpc/nct6798d/0/voltage/0) | | +- Voltage #2 : 0.984 0.976 0.984 (/lpc/nct6798d/0/voltage/1) | | +- AVCC : 3.36 3.36 3.36 (/lpc/nct6798d/0/voltage/2) | | +- +3.3V : 3.216 3.2 3.216 (/lpc/nct6798d/0/voltage/3) | | +- Voltage #5 : 1.704 1.704 1.704 (/lpc/nct6798d/0/voltage/4) | | +- Voltage #6 : 0.264 0.264 0.264 (/lpc/nct6798d/0/voltage/5) | | +- Voltage #7 : 0.936 0.936 0.936 (/lpc/nct6798d/0/voltage/6) | | +- 3VSB : 3.36 3.36 3.36 (/lpc/nct6798d/0/voltage/7) | | +- VBat : 3.104 3.104 3.104 (/lpc/nct6798d/0/voltage/8) | | +- VTT : 0.528 0.528 0.528 (/lpc/nct6798d/0/voltage/9) | | +- Voltage #11 : 0.536 0.536 0.536 (/lpc/nct6798d/0/voltage/10) | | +- Voltage #12 : 0.48 0.48 0.48 (/lpc/nct6798d/0/voltage/11) | | +- Voltage #13 : 1.056 1.056 1.064 (/lpc/nct6798d/0/voltage/12) | | +- Voltage #14 : 0.608 0.608 0.608 (/lpc/nct6798d/0/voltage/13) | | +- Voltage #15 : 0.528 0.528 0.528 (/lpc/nct6798d/0/voltage/14) | | +- CPU Core : 43 43 48 (/lpc/nct6798d/0/temperature/0) | | +- Temperature #1 : 33.5 33.5 33.5 (/lpc/nct6798d/0/temperature/1) | | +- Temperature #2 : 29 29 29 (/lpc/nct6798d/0/temperature/2) | | +- Temperature #3 : 29 29 29 (/lpc/nct6798d/0/temperature/3) | | +- Temperature #4 : 22 22 22 (/lpc/nct6798d/0/temperature/4) | | +- Temperature #5 : 28 28 28 (/lpc/nct6798d/0/temperature/5) | | +- Temperature #6 : 55 55 55 (/lpc/nct6798d/0/temperature/6) | | +- Fan #1 : 0 0 0 (/lpc/nct6798d/0/fan/0) | | +- Fan #2 : 0 0 0 (/lpc/nct6798d/0/fan/1) | | +- Fan #3 : 0 0 0 (/lpc/nct6798d/0/fan/2) | | +- Fan #4 : 0 0 0 (/lpc/nct6798d/0/fan/3) | | +- Fan #5 : 727.763 727.763 803.571 (/lpc/nct6798d/0/fan/4) | | +- Fan #6 : 0 0 0 (/lpc/nct6798d/0/fan/5) | | +- Fan #7 : 2772.07 2749.49 2800.83 (/lpc/nct6798d/0/fan/6) | | +- Fan #1 : 60 60 60 (/lpc/nct6798d/0/control/0) | | +- Fan #2 : 100 100 100 (/lpc/nct6798d/0/control/1) | | +- Fan #3 : 60 60 60 (/lpc/nct6798d/0/control/2) | | +- Fan #4 : 62.7451 61.9608 69.8039 (/lpc/nct6798d/0/control/3) | | +- Fan #5 : 34.1177 32.9412 41.9608 (/lpc/nct6798d/0/control/4) | | +- Fan #6 : 100 100 100 (/lpc/nct6798d/0/control/5) | | +- Fan #7 : 100 100 100 (/lpc/nct6798d/0/control/6) |

the snippet for my sensor handling

private void PopulateHardwareSubtree(IHardware hardware, TreeViewItem parentNode)
        {
            try
            {
                foreach (var subHardware in hardware.SubHardware)
                {
                    var subHardwareNode = new TreeViewItem
                    {
                        Header = new StackPanel
                        {
                            Orientation = Orientation.Horizontal,
                            Children =
                    {
                        new Image
                        {
                            Width = 16,
                            Height = 16,
                            Margin = new Thickness(0, 0, 5, 0),
                            Source = HardwareImage.Instance.GetImage(subHardware.HardwareType)
                        },
                        new TextBlock { Text = subHardware.Name }
                    }
                        }
                    };

                    PopulateHardwareSubtree(subHardware, subHardwareNode);

                    parentNode.Items.Add(subHardwareNode);

                    // Process sensors for the current sub-hardware
                    foreach (var sensor in subHardware.Sensors)
                    {
                        ProcessSensor(sensor, subHardwareNode);
                    }
                }

                // Process sensors for the main hardware
                foreach (var sensor in hardware.Sensors)
                {
                    ProcessSensor(sensor, parentNode);
                }

                // Dictionary to store DataGrids for each sensor type
                Dictionary<string, DataGrid> sensorDataGrids = new Dictionary<string, DataGrid>();

                foreach (var sensor in hardware.Sensors)
                {
                    string sensorTypeKey = sensor.SensorType.ToString(); // Use the enum name as the key

                    string formattedValue = sensorNodes.ValueToString(sensor.Value, sensor.SensorType);
                    string formattedMin = sensorNodes.ValueToString(sensor.Min, sensor.SensorType);
                    string formattedMax = sensorNodes.ValueToString(sensor.Max, sensor.SensorType);

                    log.Info($"Sensor: {sensor.Name}, Type: {sensor.SensorType}, Value: {formattedValue}, Min: {formattedMin}, Max: {formattedMax}");

                    // Check if the DataGrid for the sensor type exists, otherwise create one
                    if (!sensorDataGrids.TryGetValue(sensorTypeKey, out var sensorDataGrid))
                    {
                        // Create a new DataGrid
                        sensorDataGrid = new DataGrid
                        {
                            AutoGenerateColumns = false,
                            CanUserAddRows = false,
                            IsReadOnly = true, // Allow editing
                            AlternatingRowBackground = Brushes.LightGray, // Set alternating row color

                            // Define columns for the DataGrid
                            Columns =
                    {
                        new DataGridTextColumn
                        {
                            Header = "Sensor Name",
                            Binding = new System.Windows.Data.Binding("SensorName")
                        },
                        new DataGridTextColumn
                        {
                            Header = "Value",
                            Binding = new System.Windows.Data.Binding("Value")
                        },
                        new DataGridTextColumn
                        {
                            Header = "Min",
                            Binding = new System.Windows.Data.Binding("Min")
                        },
                        new DataGridTextColumn
                        {
                            Header = "Max",
                            Binding = new System.Windows.Data.Binding("Max")
                        }
                    }
                        };

                        // Add the DataGrid to the parent node
                        AddImagePanelToParent(parentNode, new StackPanel { Children = { sensorDataGrid } }, sensorTypeKey, sensor.SensorType);

                        // Store the DataGrid in the dictionary for future use
                        sensorDataGrids[sensorTypeKey] = sensorDataGrid;
                    }

                    // Add the current sensor node to the corresponding DataGrid
                    sensorDataGrid.Items.Add(new SensorNodes.SensorData
                    {
                        SensorName = sensor.Name,
                        Value = formattedValue,
                        Min = formattedMin,
                        Max = formattedMax
                    });
                }
            }
            catch (Exception ex)
            {
                log.Error("An error occurred in PopulateHardwareSubtree", ex);
                // Handle the exception as needed, e.g., show a message box or log the error
            }
        }

OminiData avatar Nov 26 '23 11:11 OminiData