コード例 #1
0
ファイル: OneWire.Sample.cs プロジェクト: skang0401/iot
        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");
                        }
                    }
                }
            }
        }
コード例 #2
0
        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;
            }
        }