static async Task Main(string[] args) { // Make sure you can access the bus device before requesting a device scan (or run using sudo) // $ sudo chmod a+rw /sys/bus/w1/devices/w1_bus_master1/w1_master_* if (args.Any(_ => _ == "temp")) { // Quick and simple way to find a thermometer and print the temperature foreach (var dev in OneWireThermometerDevice.EnumerateDevices()) { Console.WriteLine($"Temperature reported by '{dev.DeviceId}': " + (await dev.ReadTemperatureAsync()).Celsius.ToString("F2") + "\u00B0C"); } } else { // More advanced way, with rescanning the bus and iterating devices per 1-wire bus foreach (var busId in OneWireBus.EnumerateBusIds()) { var bus = new OneWireBus(busId); Console.WriteLine($"Found bus '{bus.BusId}', scanning for devices ..."); await bus.ScanForDeviceChangesAsync(); foreach (var devId in bus.EnumerateDeviceIds()) { var dev = new OneWireDevice(busId, devId); Console.WriteLine($"Found family '{dev.Family}' device '{dev.DeviceId}' on '{bus.BusId}'"); if (OneWireThermometerDevice.IsCompatible(busId, devId)) { var devTemp = new OneWireThermometerDevice(busId, devId); Console.WriteLine("Temperature reported by device: " + (await devTemp.ReadTemperatureAsync()).Celsius.ToString("F2") + "\u00B0C"); } } } } }
public async Task DS18B20SicaklikOku() { try { string busId = OneWireBus.EnumerateBusIds().First(); string deviceId = OneWireDevice.EnumerateDeviceIds().First().devId; OneWireThermometerDevice ds18B20Dev = new OneWireThermometerDevice(busId, deviceId); Temperature sicaklik = await ds18B20Dev.ReadTemperatureAsync(); Sicaklik = sicaklik.Celsius; } catch (Exception hata) { SonHata = hata; } }
// GET: Fermenters1 public async Task <IActionResult> Index() { var brewOSContext = _context.Fermenters .Include(f => f.TempSensor) .Include(f => f.Wort) .Include(f => f.Wort._Recipe) .Include(f => f.Wort._Recipe.Style); OneWireBus bus = OneWireBus.Instance; foreach (var item in brewOSContext) { if (!bus.Devices.Select(x => x.Address).Contains(item.Address)) { bus.Devices.Add(new TempSensorDS18B20(item.TempSensor.Address)); } } return(View(await brewOSContext.ToListAsync())); }
/// <summary> /// Create a new DS18B20 temperature sensor object with the specified configuration. /// </summary> /// <param name="oneWirePin">GPIO pin the DS18B20 is connected to.</param> /// <param name="deviceID">Address of the DS18B20 device.</param> /// <param name="updateInterval">Update period in milliseconds. Note that this most be greater than the conversion period for the sensor.</param> /// <param name="temperatureChangeNotificationThreshold">Threshold for temperature changes that will generate an interrupt.</param> public DS18B20(Cpu.Pin oneWirePin, UInt64 deviceID = 0, ushort updateInterval = MinimumPollingPeriod, float temperatureChangeNotificationThreshold = 0.001F) { if (oneWirePin == Cpu.Pin.GPIO_NONE) { throw new ArgumentException("OneWire pin cannot be null.", nameof(oneWirePin)); } lock (OneWireBus.Instance) { Sensor = OneWireBus.Add(oneWirePin); if (Sensor.DeviceBus.TouchReset() == 0) { throw new Exception("Cannot find DS18B20 sensor on the OneWire interface."); } if (Sensor.DeviceIDs.Count == 1) { BusMode = BusModeType.SingleDevice; } else { if (deviceID == 0) { throw new ArgumentException("Device deviceID cannot be 0 on a OneWireBus with multiple devices.", nameof(deviceID)); } BusMode = BusModeType.MultimpleDevices; } // // Check for the ROM ID in the list of devices connected to the bus. // if (deviceID != 0) { bool found = false; foreach (UInt64 id in Sensor.DeviceIDs) { if (id == deviceID) { found = true; break; } } if (!found) { throw new Exception("Cannot locate the specified device ID on the OneWire bus."); } } } DeviceID = deviceID; ReadConfiguration(); if ((updateInterval != 0) && (MaximumConversionPeriod > updateInterval)) { throw new ArgumentOutOfRangeException(nameof(updateInterval), "Temperature readings can take " + MaximumConversionPeriod + "ms at this resolution."); } TemperatureChangeNotificationThreshold = temperatureChangeNotificationThreshold; _updateInterval = updateInterval; if (updateInterval > 0) { StartUpdating(); } else { Update(); } }
public Startup(IConfiguration configuration) { OneWireBus.InitializeBus(2000); Configuration = configuration; }