internal double Update() { double value = -1; if (this.sensorID == null) { this.Reload(this.api); } if (this.sensorID == null) { return(value); } try { WMIQuery wmiQuery = new WMIQuery(this.ns, SensorClass); wmiQuery.Where("Identifier", this.sensorID); using (var sensor = wmiQuery.GetAt(0)) if (sensor != null) { value = Double.Parse(sensor.GetPropertyValue("Value").ToString()); } } catch (Exception ex) { api.Log(API.LogType.Error, "Fatal Error: " + ex.ToString()); } return(value); }
internal void Reload(Rainmeter.API rm) { api = rm; try { string hwType = rm.ReadString("HardwareType", ""); string hwName = rm.ReadString("HardwareName", ""); int hwIndex = rm.ReadInt("HardwareIndex", 0); string sType = rm.ReadString("SensorType", ""); string sName = rm.ReadString("SensorName", ""); int sIndex = rm.ReadInt("SensorIndex", 0); api.Log(API.LogType.Debug, String.Format("Hardware(type, name, index): ({0}, {1}, {2}), Sensor(type, name, index): ({3}, {4}, {5})", hwType, hwName, hwIndex, sType, sName, sIndex)); this.ns = wmiROOT + "\\" + rm.ReadString("Namespace", DefaultNamespace); WMIQuery hwQuery = new WMIQuery(this.ns, HardwareClass); if (hwType.Length > 0) { hwQuery.Where("HardwareType", hwType); } if (hwName.Length > 0) { hwQuery.Where("name", hwName); } api.Log(API.LogType.Debug, "Hardware Query: " + hwQuery.ToString()); string hardwareID; using (var hardware = hwQuery.GetAt(hwIndex)) { if (hardware == null) { api.Log(API.LogType.Error, "can't find hardware -> check hardware filter, check if OHM/LHM is running"); this.sensorID = null; return; } hardwareID = (string)hardware.GetPropertyValue("Identifier"); api.Log(API.LogType.Debug, "Hardware Identifier: " + hardwareID.ToString()); } WMIQuery sQuery = new WMIQuery(this.ns, SensorClass); sQuery.Where("Parent", hardwareID); if (sType.Length > 0) { sQuery.Where("SensorType", sType); } if (sName.Length > 0) { sQuery.Where("name", sName); } api.Log(API.LogType.Debug, "Sensor Query: " + sQuery.ToString()); using (var sensor = sQuery.GetAt(sIndex)) { if (sensor == null) { api.Log(API.LogType.Error, "can't find sensor -> check sensor filter"); this.sensorID = null; return; } this.sensorID = sensor.GetPropertyValue("Identifier").ToString(); api.Log(API.LogType.Debug, "Sensor Identifier: " + sensorID.ToString()); } } catch (Exception ex) { api.Log(API.LogType.Error, "Fatal Error: " + ex.Message); api.Log(API.LogType.Debug, ex.ToString()); } }