示例#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);
            }
        }
示例#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);
            }
        }
示例#3
0
        public AsusSensorInfo GetSensorInfo(byte index)
        {
            AsusSensorInfo sensor = new AsusSensorInfo();

            try
            {
                ManagementBaseObject res = InvokeMethod(instance, "sensor_get_info", "Index", index);
                if (res != null)
                {
                    sensor.Index    = index;
                    sensor.DataType = (AsusSensorDataType)res["Data_Type"];
                    sensor.Location = (AsusSensorLocation)res["Location"];
                    sensor.Name     = (string)res["Name"];
                    sensor.Source   = (AsusSensorSource)res["Source"];
                    sensor.Type     = (AsusSensorType)res["Type"];
                    sensor.Value    = GetSensorFormattedValue(sensor);
                }
            }
            catch
            {
                // ignored
            }

            return(sensor);
        }
示例#4
0
 public string GetSensorFormattedValue(AsusSensorInfo sensor)
 {
     return(SensorValueToFormattedString(sensor.Type, GetSensorValue(sensor.Index)));
 }