Beispiel #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);
            }
        }
Beispiel #2
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();
        }
Beispiel #3
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;
            }
        }