static void Main(string[] args) { Ds18b20Connection Tconnection = new Ds18b20Connection(0); // first thermometer Console.WriteLine("Ds18b20 Sample: 1wire digital temperature sensor "); Console.WriteLine(); while (!Console.KeyAvailable) { UnitsNet.Temperature T = Tconnection.GetTemperature(); Console.WriteLine("{0} , {1} °C", T.ToString(), T.DegreesCelsius.ToString()); Console.WriteLine(); } }
/// <summary> /// Costruttore senza ID del sensore, trovato automaticamente dal software /// Prende il primo termometro che trova /// </summary> /// <param name="Name"></param> /// <param name="Simulation"></param> /// <param name="Logger"></param> public Temperature_DS1822(string Name, bool Simulation, Logger Logger) : base(Name, Simulation, Logger) { Logger.Debug("Temperature_DS1822_Constructor senza ID. SensorId automatico"); if (!Simulation) { // creazione del termometro; se il parametro DeviceIndex = 0 usa il primo sensore che trova try { termometro = new Ds18b20Connection(0); } catch (Exception ex) { Logger.Error("Temperature_DS1822_Constructor senza ID. " + ex.Message); return; } } Initialization(); }
public Temperature_DS1822(string Name, bool Simulation, string SensorId,Logger Logger) : base(Name, Simulation, Logger) { Logger.Debug("Temperature_DS1822_Constructor con ID. SensorId: " + SensorId); // creazione del termometro con l'Id passato if (!Simulation) { try { termometro = new Ds18b20Connection(SensorId); } catch (Exception ex) { Logger.Error("Temperature_DS1822_Constructor con ID. SensorId" + ex.Message); return; } } IdSensor = SensorId; Initialization(); }
private void Init() { this.connection = new Ds18b20Connection(_deviceID); }