Example #1
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);
            }
        }
Example #2
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);
            }
        }
Example #3
0
        private string GetWmiInstanceName()
        {
            try
            {
                instanceName = WMI.GetInstanceName(wmiScope, wmiAMDACPI);
            }
            catch { }

            return(instanceName);
        }
Example #4
0
        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);
            }
        }
Example #5
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();
        }