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); } }
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); } }
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); }
public string GetSensorFormattedValue(AsusSensorInfo sensor) { return(SensorValueToFormattedString(sensor.Type, GetSensorValue(sensor.Index))); }