Exemple #1
0
        public bool Init()
        {
            try
            {
                WMI.Connect(scope);

                instanceName = WMI.GetInstanceName(scope, className);
                instance     = new ManagementObject(scope, $"{className}.InstanceName='{instanceName}'", null);

                if (instanceName.Length == 0 || instance == null)
                {
                    throw new Exception($"No instance for WMI class {className}");
                }

                uint count = GetItemCount();
                for (byte i = 0; i < count; i++)
                {
                    AsusSensorInfo sensor = GetSensorInfo(i);
                    sensors.Add(sensor);
                }

                sensors.Sort((a, b) => a.Type.CompareTo(b.Type));

                Status = 1;
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemple #2
0
        public bool Init()
        {
            try
            {
                instanceName = WMI.GetInstanceName(scope, className);
                instance     = new ManagementObject(scope, $"{className}.InstanceName='{instanceName}'", null);

                if (instanceName.Length == 0 || instance == null)
                {
                    throw new Exception($"No instance for WMI class {className}");
                }

                uint count = GetItemCount();
                for (byte i = 0; i < count; i++)
                {
                    AsusSensorInfo sensor = GetSensorInfo(i);
                    sensors.Add(sensor);
                    sensors = sensors.OrderBy(o => o.Type).ToList();
                }

                Status = 1;
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemple #3
0
        private string GetWmiInstanceName()
        {
            try
            {
                instanceName = WMI.GetInstanceName(wmiScope, wmiAMDACPI);
            }
            catch { }

            return(instanceName);
        }
Exemple #4
0
        private void PrintWmiFunctions()
        {
            try
            {
                classInstance = new ManagementObject(wmiScope,
                                                     $"{wmiAMDACPI}.InstanceName='{instanceName}'",
                                                     null);

                // Get function names with their IDs
                string[] functionObjects = { "GetObjectID", "GetObjectID2" };
                int      index           = 1;

                foreach (var functionObject in functionObjects)
                {
                    AddHeading($"WMI: Bios Functions {index}");

                    try
                    {
                        pack = WMI.InvokeMethod(classInstance, functionObject, "pack", null, 0);

                        if (pack != null)
                        {
                            uint[]   ID       = (uint[])pack.GetPropertyValue("ID");
                            string[] IDString = (string[])pack.GetPropertyValue("IDString");
                            byte     Length   = (byte)pack.GetPropertyValue("Length");

                            for (var i = 0; i < Length; ++i)
                            {
                                if (IDString[i] == "")
                                {
                                    return;
                                }
                                AddLine($"{IDString[i]}: {ID[i]:X8}");
                            }
                        }
                        else
                        {
                            AddLine("<FAILED>");
                        }
                    }
                    catch { }

                    index++;
                    AddLine();
                }
            }
            catch { }
        }
        private void ReadMemoryConfig()
        {
            string scope     = "root\\wmi";
            string className = "AMD_ACPI";

            try
            {
                string instanceName = WMI.GetInstanceName(scope, className);

                ManagementBaseObject pack;
                ManagementObject     classInstance = new ManagementObject(scope,
                                                                          $"{className}.InstanceName='{instanceName}'",
                                                                          null);

                // Get possible values (index) of a memory option in BIOS

                /*pack = WMI.InvokeMethod(classInstance, "Getdvalues", "pack", "ID", 0x20007);
                 * if (pack != null)
                 * {
                 *  uint[] DValuesBuffer = (uint[])pack.GetPropertyValue("DValuesBuffer");
                 *  for (var i = 0; i < DValuesBuffer.Length; i++)
                 *  {
                 *      Debug.WriteLine("{0}", DValuesBuffer[i]);
                 *  }
                 * }*/


                // Get function names with their IDs
                string[] functionObjects = { "GetObjectID", "GetObjectID2" };
                foreach (var functionObject in functionObjects)
                {
                    try
                    {
                        pack = WMI.InvokeMethod(classInstance, functionObject, "pack", null, 0);
                        if (pack != null)
                        {
                            uint[]   ID       = (uint[])pack.GetPropertyValue("ID");
                            string[] IDString = (string[])pack.GetPropertyValue("IDString");
                            byte     Length   = (byte)pack.GetPropertyValue("Length");

                            Debug.WriteLine("----------------------------");
                            Debug.WriteLine("WMI: BIOS Functions");
                            Debug.WriteLine("----------------------------");

                            for (var i = 0; i < Length; ++i)
                            {
                                biosFunctions.Add(new BiosACPIFunction(IDString[i], ID[i]));
                                Debug.WriteLine("{0}: {1:X8}", IDString[i], ID[i]);
                            }
                        }
                    }
                    catch { }
                }

                // Get APCB config from BIOS. Holds memory parameters.
                BiosACPIFunction cmd = GetFunctionByIdString("Get APCB Config");
                if (cmd == null)
                {
                    throw new Exception();
                }

                BMC.Table = WMI.RunCommand(classInstance, cmd.ID);
                var allZero = !BMC.Table.Any(v => v != 0);

                // When ProcODT is 0, then all other resistance values are 0
                // Happens when one DIMM installed in A1 or A2 slot
                if (allZero || BMC.Table == null || BMC.Config.ProcODT < 1)
                {
                    BMC.Table = null;
                    throw new Exception();
                }

                textBoxProcODT.Text = BMC.GetProcODTString(BMC.Config.ProcODT);

                textBoxClkDrvStren.Text      = BMC.GetDrvStrenString(BMC.Config.ClkDrvStren);
                textBoxAddrCmdDrvStren.Text  = BMC.GetDrvStrenString(BMC.Config.AddrCmdDrvStren);
                textBoxCsOdtCmdDrvStren.Text = BMC.GetDrvStrenString(BMC.Config.CsOdtCmdDrvStren);
                textBoxCkeDrvStren.Text      = BMC.GetDrvStrenString(BMC.Config.CkeDrvStren);

                textBoxRttNom.Text  = BMC.GetRttString(BMC.Config.RttNom);
                textBoxRttWr.Text   = BMC.GetRttWrString(BMC.Config.RttWr);
                textBoxRttPark.Text = BMC.GetRttString(BMC.Config.RttPark);

                textBoxAddrCmdSetup.Text = $"{BMC.Config.AddrCmdSetup}";
                textBoxCsOdtSetup.Text   = $"{BMC.Config.CsOdtSetup}";
                textBoxCkeSetup.Text     = $"{BMC.Config.CkeSetup}";
            }
            catch (Exception ex)
            {
                compatMode = true;
                AdonisUI.Controls.MessageBox.Show(
                    "Failed to read AMD ACPI. Some parameters will be empty.",
                    "Warning",
                    AdonisUI.Controls.MessageBoxButton.OK,
                    AdonisUI.Controls.MessageBoxImage.Warning);
                Console.WriteLine(ex.Message);
            }
        }
        private void ReadMemoryModulesInfo()
        {
            using (var searcher = new ManagementObjectSearcher("select * from Win32_PhysicalMemory"))
            {
                try
                {
                    foreach (var queryObject in searcher.Get().Cast <ManagementObject>())
                    {
                        ulong  capacity      = 0UL;
                        uint   clockSpeed    = 0U;
                        string partNumber    = "N/A";
                        string bankLabel     = "";
                        string manufacturer  = "";
                        string deviceLocator = "";
                        object temp;

                        temp = WMI.TryGetProperty(queryObject, "Capacity");
                        if (temp != null)
                        {
                            capacity = (ulong)temp;
                        }

                        temp = WMI.TryGetProperty(queryObject, "ConfiguredClockSpeed");
                        if (temp != null)
                        {
                            clockSpeed = (uint)temp;
                        }

                        temp = WMI.TryGetProperty(queryObject, "partNumber");
                        if (temp != null)
                        {
                            partNumber = (string)temp;
                        }

                        temp = WMI.TryGetProperty(queryObject, "BankLabel");
                        if (temp != null)
                        {
                            bankLabel = (string)temp;
                        }

                        temp = WMI.TryGetProperty(queryObject, "Manufacturer");
                        if (temp != null)
                        {
                            manufacturer = (string)temp;
                        }

                        temp = WMI.TryGetProperty(queryObject, "DeviceLocator");
                        if (temp != null)
                        {
                            deviceLocator = (string)temp;
                        }

                        modules.Add(new MemoryModule(partNumber, bankLabel, manufacturer, deviceLocator, capacity, clockSpeed));

                        string bl = bankLabel.Length > 0 ? new string(bankLabel.Where(char.IsDigit).ToArray()) : "";
                        //string dl = deviceLocator.Length > 0 ? new string(deviceLocator.Where(char.IsDigit).ToArray()) : "";

                        comboBoxPartNumber.Items.Add($"#{bl}: {partNumber}");

                        comboBoxPartNumber.SelectedIndex = 0;
                    }

                    if (modules.Count > 0)
                    {
                        var totalCapacity = 0UL;

                        foreach (var module in modules)
                        {
                            totalCapacity += module.Capacity;
                        }

                        if (modules.FirstOrDefault().ClockSpeed != 0)
                        {
                            MEMCFG.Frequency = modules.FirstOrDefault().ClockSpeed;
                        }

                        if (totalCapacity != 0)
                        {
                            MEMCFG.TotalCapacity = $"{totalCapacity / 1024 / (1024 * 1024)}GB";
                        }
                    }
                }
                catch
                {
                    AdonisUI.Controls.MessageBox.Show("Failed to get installed memory parameters. Corresponding fields will be empty.",
                                                      "Warning",
                                                      AdonisUI.Controls.MessageBoxButton.OK,
                                                      AdonisUI.Controls.MessageBoxImage.Warning);
                }
            }
        }
Exemple #7
0
        private void ReadMemoryModulesInfo()
        {
            using (var searcher = new ManagementObjectSearcher("select * from Win32_PhysicalMemory"))
            {
                try
                {
                    foreach (var queryObject in searcher.Get().Cast <ManagementObject>())
                    {
                        ulong  capacity   = 0UL;
                        uint   clockSpeed = 0U;
                        string partNumber = "N/A";
                        object temp;

                        temp = WMI.TryGetProperty(queryObject, "Capacity");
                        if (temp != null)
                        {
                            capacity = (ulong)temp;
                        }

                        temp = WMI.TryGetProperty(queryObject, "ConfiguredClockSpeed");
                        if (temp != null)
                        {
                            clockSpeed = (uint)temp;
                        }

                        temp = WMI.TryGetProperty(queryObject, "partNumber");
                        if (temp != null)
                        {
                            partNumber = (string)temp;
                        }

                        modules.Add(new MemoryModule(partNumber, capacity, clockSpeed));
                        comboBoxPartNumber.Items.Add($"{partNumber}");
                        comboBoxPartNumber.SelectedIndex = 0;
                    }

                    if (modules.Count > 0)
                    {
                        var totalCapacity = 0UL;

                        foreach (var module in modules)
                        {
                            totalCapacity += module.Capacity;
                        }

                        if (modules.FirstOrDefault().ClockSpeed != 0)
                        {
                            MEMCFG.Frequency = modules.FirstOrDefault().ClockSpeed;
                        }

                        if (totalCapacity != 0)
                        {
                            MEMCFG.TotalCapacity = $"{totalCapacity / 1024 / (1024 * 1024)}GB";
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("Failed to get installed memory parameters. Corresponding fields will be empty.",
                                    "Warning",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Warning);
                }
            }
        }
Exemple #8
0
        private void ReadMemoryConfig()
        {
            var scope     = @"root\wmi";
            var className = "AMD_ACPI";

            try
            {
                WMI.Connect($@"{scope}");

                var instanceName = WMI.GetInstanceName(scope, className);

                var classInstance = new ManagementObject(scope,
                                                         $"{className}.InstanceName='{instanceName}'",
                                                         null);

                // Get possible values (index) of a memory option in BIOS

                /*pack = WMI.InvokeMethod(classInstance, "Getdvalues", "pack", "ID", 0x20007);
                 * if (pack != null)
                 * {
                 *  uint[] DValuesBuffer = (uint[])pack.GetPropertyValue("DValuesBuffer");
                 *  for (var i = 0; i < DValuesBuffer.Length; i++)
                 *  {
                 *      Debug.WriteLine("{0}", DValuesBuffer[i]);
                 *  }
                 * }
                 */


                // Get function names with their IDs
                string[] functionObjects = { "GetObjectID", "GetObjectID2" };
                foreach (var functionObject in functionObjects)
                {
                    try
                    {
                        var pack = WMI.InvokeMethod(classInstance, functionObject, "pack", null, 0);
                        if (pack != null)
                        {
                            var ID       = (uint[])pack.GetPropertyValue("ID");
                            var IDString = (string[])pack.GetPropertyValue("IDString");
                            var Length   = (byte)pack.GetPropertyValue("Length");

                            for (var i = 0; i < Length; ++i)
                            {
                                biosFunctions.Add(new BiosACPIFunction(IDString[i], ID[i]));
                                Debug.WriteLine("{0}: {1:X8}", IDString[i], ID[i]);
                            }
                        }
                    }
                    catch
                    {
                        // ignored
                    }
                }

                // Get APCB config from BIOS. Holds memory parameters.
                BiosACPIFunction cmd = GetFunctionByIdString("Get APCB Config");
                if (cmd == null)
                {
                    throw new Exception();
                }

                var apcbConfig = WMI.RunCommand(classInstance, cmd.ID);

                cmd = GetFunctionByIdString("Get memory voltages");
                if (cmd != null)
                {
                    var voltages = WMI.RunCommand(classInstance, cmd.ID);

                    // MEM_VDDIO is ushort, offset 27
                    // MEM_VTT is ushort, offset 29
                    for (var i = 27; i <= 30; i++)
                    {
                        var value = voltages[i];
                        if (value > 0)
                        {
                            apcbConfig[i] = value;
                        }
                    }
                }

                BMC.Table = apcbConfig;

                // When ProcODT is 0, then all other resistance values are 0
                // Happens when one DIMM installed in A1 or A2 slot
                if (BMC.Table == null || cpu.utils.AllZero(BMC.Table) || BMC.Config.ProcODT < 1)
                {
                    throw new Exception();
                }

                var vdimm = Convert.ToSingle(Convert.ToDecimal(BMC.Config.MemVddio) / 1000);
                if (vdimm > 0)
                {
                    textBoxMemVddio.Text = $"{vdimm:F4}V";
                }
                else if (AsusWmi != null && AsusWmi.Status == 1)
                {
                    var sensor = AsusWmi.FindSensorByName("DRAM Voltage");
                    if (sensor != null)
                    {
                        textBoxMemVddio.Text = sensor.Value;
                    }
                    else
                    {
                        labelMemVddio.IsEnabled = false;
                    }
                }
                else
                {
                    labelMemVddio.IsEnabled = false;
                }

                var vtt = Convert.ToSingle(Convert.ToDecimal(BMC.Config.MemVtt) / 1000);
                if (vtt > 0)
                {
                    textBoxMemVtt.Text = $"{vtt:F4}V";
                }
                else
                {
                    labelMemVtt.IsEnabled = false;
                }

                textBoxProcODT.Text = BMC.GetProcODTString(BMC.Config.ProcODT);

                textBoxClkDrvStren.Text      = BMC.GetDrvStrenString(BMC.Config.ClkDrvStren);
                textBoxAddrCmdDrvStren.Text  = BMC.GetDrvStrenString(BMC.Config.AddrCmdDrvStren);
                textBoxCsOdtCmdDrvStren.Text = BMC.GetDrvStrenString(BMC.Config.CsOdtCmdDrvStren);
                textBoxCkeDrvStren.Text      = BMC.GetDrvStrenString(BMC.Config.CkeDrvStren);

                textBoxRttNom.Text  = BMC.GetRttString(BMC.Config.RttNom);
                textBoxRttWr.Text   = BMC.GetRttWrString(BMC.Config.RttWr);
                textBoxRttPark.Text = BMC.GetRttString(BMC.Config.RttPark);

                textBoxAddrCmdSetup.Text = $"{BMC.Config.AddrCmdSetup}";
                textBoxCsOdtSetup.Text   = $"{BMC.Config.CsOdtSetup}";
                textBoxCkeSetup.Text     = $"{BMC.Config.CkeSetup}";
            }
            catch (Exception ex)
            {
                compatMode = true;

                MessageBox.Show(
                    "Failed to read AMD ACPI. Odt, Setup and Drive strength parameters will be empty.",
                    "Warning",
                    MessageBoxButton.OK,
                    MessageBoxImage.Warning);
                Console.WriteLine(ex.Message);
            }

            BMC.Dispose();
        }
Exemple #9
0
        private void ReadMemoryModulesInfo()
        {
            using (var searcher = new ManagementObjectSearcher("select * from Win32_PhysicalMemory"))
            {
                bool connected = false;
                try
                {
                    WMI.Connect(@"root\cimv2");

                    connected = true;

                    foreach (var queryObject in searcher.Get().Cast <ManagementObject>())
                    {
                        var capacity      = 0UL;
                        var clockSpeed    = 0U;
                        var partNumber    = "N/A";
                        var bankLabel     = "";
                        var manufacturer  = "";
                        var deviceLocator = "";

                        var temp = WMI.TryGetProperty(queryObject, "Capacity");
                        if (temp != null)
                        {
                            capacity = (ulong)temp;
                        }

                        temp = WMI.TryGetProperty(queryObject, "ConfiguredClockSpeed");
                        if (temp != null)
                        {
                            clockSpeed = (uint)temp;
                        }

                        temp = WMI.TryGetProperty(queryObject, "partNumber");
                        if (temp != null)
                        {
                            partNumber = (string)temp;
                        }

                        temp = WMI.TryGetProperty(queryObject, "BankLabel");
                        if (temp != null)
                        {
                            bankLabel = (string)temp;
                        }

                        temp = WMI.TryGetProperty(queryObject, "Manufacturer");
                        if (temp != null)
                        {
                            manufacturer = (string)temp;
                        }

                        temp = WMI.TryGetProperty(queryObject, "DeviceLocator");
                        if (temp != null)
                        {
                            deviceLocator = (string)temp;
                        }

                        modules.Add(new MemoryModule(partNumber.Trim(), bankLabel.Trim(), manufacturer.Trim(),
                                                     deviceLocator, capacity, clockSpeed));

                        //string bl = bankLabel.Length > 0 ? new string(bankLabel.Where(char.IsDigit).ToArray()) : "";
                        //string dl = deviceLocator.Length > 0 ? new string(deviceLocator.Where(char.IsDigit).ToArray()) : "";

                        //comboBoxPartNumber.Items.Add($"#{bl}: {partNumber}");
                        //comboBoxPartNumber.SelectedIndex = 0;
                    }
                }
                catch (Exception ex)
                {
                    var title = connected ? @"Failed to get installed memory parameters." : $@"{ex.Message}";
                    MessageBox.Show(
                        title,
                        "Warning",
                        MessageBoxButton.OK,
                        MessageBoxImage.Warning);
                }
            }

            if (modules.Count > 0)
            {
                ReadChannelsInfo();

                var totalCapacity = 0UL;

                foreach (var module in modules)
                {
                    var rank = module.DualRank ? "DR" : "SR";
                    totalCapacity += module.Capacity;
                    comboBoxPartNumber.Items.Add(
                        $"{module.Slot}: {module.PartNumber} ({module.Capacity / 1024 / (1024 * 1024)}GB, {rank})");
                }

                if (modules[0].ClockSpeed != 0)
                {
                    MEMCFG.Frequency = modules[0].ClockSpeed;
                }

                if (totalCapacity != 0)
                {
                    MEMCFG.TotalCapacity = $"{totalCapacity / 1024 / (1024 * 1024)}GB";
                }

                comboBoxPartNumber.SelectedIndex     = 0;
                comboBoxPartNumber.SelectionChanged += ComboBoxPartNumber_SelectionChanged;
            }
        }
Exemple #10
0
        private void Debug(object sender, DoWorkEventArgs e)
        {
            result = $"{Application.ProductName} v{Application.ProductVersion} Debug Report" +
                     Environment.NewLine +
                     Environment.NewLine;

            Type type = SI.GetType();

            PropertyInfo[] properties = type.GetProperties();

            AddHeading("System Info");
            try
            {
                foreach (PropertyInfo property in properties)
                {
                    if (property.Name == "CpuId" || property.Name == "PatchLevel")
                    {
                        AddLine(property.Name + ": " + $"{property.GetValue(SI, null):X8}");
                    }
                    else if (property.Name == "SmuVersion")
                    {
                        AddLine(property.Name + ": " + SI.GetSmuVersionString());
                    }
                    else
                    {
                        AddLine(property.Name + ": " + property.GetValue(SI, null));
                    }
                }
            }
            catch
            {
                AddLine("<FAILED>");
            }
            AddLine();

            // DRAM modules info
            AddHeading("Memory Modules");

            foreach (MemoryModule module in modules)
            {
                AddLine($"{module.PartNumber} {module.Capacity / 1024 / (1024 * 1024)}GB {module.ClockSpeed}MHz");
            }
            AddLine();

            // Memory timings info
            AddHeading("Memory Config");
            type       = MEMCFG.GetType();
            properties = type.GetProperties();

            try
            {
                AddLine($"DRAM Base Address: {baseAddress:X8}");
                foreach (PropertyInfo property in properties)
                {
                    AddLine(property.Name + ": " + property.GetValue(MEMCFG, null));
                }
            }
            catch
            {
                AddLine("<FAILED>");
            }
            AddLine();

            // Configured DRAM memory controller settings from BIOS
            AddHeading("BIOS: Memory Controller Config");
            try
            {
                for (int i = 0; i < BMC.Table.Length; ++i)
                {
                    AddLine($"Index {i:D3}: {BMC.Table[i]:X2} ({BMC.Table[i]})");
                }
            }
            catch
            {
                AddLine("<FAILED>");
            }
            AddLine();

            // SMU power table
            AddHeading("SMU: Power Table");
            try
            {
                for (int i = 0; i < PT.Table.Length; ++i)
                {
                    byte[] temp = BitConverter.GetBytes(PT.Table[i]);
                    AddLine($"Offset {i * 0x4:X3}: {BitConverter.ToSingle(temp, 0):F8}");
                }
            }
            catch
            {
                AddLine("<FAILED>");
            }
            AddLine();

            // SMU power table
            AddHeading("SMU: Power Table Detected Values");
            try
            {
                AddLine($"MCLK: {PT.MCLK}");
                AddLine($"FCLK: {PT.FCLK}");
                AddLine($"UCLK: {PT.UCLK}");
                AddLine($"VSOC_SMU: {PT.VDDCR_SOC}");
                AddLine($"CLDO_VDDP: {PT.CLDO_VDDP}");
                AddLine($"CLDO_VDDG: {PT.CLDO_VDDG}");
            }
            catch
            {
                AddLine("<FAILED>");
            }
            AddLine();

            // All WMI classes in root namespace

            /*AddHeading("WMI: Root Classes");
             * List<string> namespaces = WMI.GetClassNamesWithinWmiNamespace(wmiScope);
             *
             * foreach (var ns in namespaces)
             * {
             *  AddLine(ns);
             * }
             * AddLine();*/

            // Check if AMD_ACPI class exists
            AddHeading("WMI: AMD_ACPI");
            if (WMI.Query(wmiScope, wmiAMDACPI) != null)
            {
                AddLine("OK");
            }
            else
            {
                AddLine("<FAILED>");
            }
            AddLine();

            AddHeading("WMI: Instance Name");
            try
            {
                var wmiInstanceName = GetWmiInstanceName();
                if (wmiInstanceName.Length == 0)
                {
                    wmiInstanceName = "<FAILED>";
                }
                AddLine(wmiInstanceName);
            }
            catch
            {
                AddLine("<FAILED>");
            }
            AddLine();

            PrintWmiFunctions();
            AddLine();

            AddHeading("SVI2: PCI Range");
            try
            {
                uint startAddress = 0x0005A000;
                uint endAddress   = 0x0005A0FF;
                while (startAddress <= endAddress)
                {
                    var data = OPS.ReadDword(startAddress);
                    AddLine($"0x{startAddress:X8}: 0x{data:X8}");
                    startAddress += 4;
                }
            }
            catch
            {
                AddLine("<FAILED>");
            }

            Invoke(new MethodInvoker(delegate
            {
                textBoxDebugOutput.Text = result;
                SetControlsState();
            }));
        }