Exemplo n.º 1
0
        // ReSharper restore InconsistentNaming

        public static DS18X20[] FindAll(OneWire bus)
        {
            if (bus == null)
            {
                throw new ArgumentNullException("bus");
            }

            var       devices        = new ArrayList();
            ArrayList presensePulses = bus.FindAllDevices();

            foreach (byte[] presensePulse in presensePulses)
            {
                if (presensePulse[0] != DS18S20FamilyCode &&
                    presensePulse[0] != DS18B20FamilyCode)
                {
                    continue;
                }

                var device = new DS18X20(presensePulse, bus);
                devices.Add(device);
            }

            var result = (DS18X20[])devices.ToArray(typeof(DS18X20));

            return(result);
        }
Exemplo n.º 2
0
        // ReSharper restore InconsistentNaming

        public static DS18X20[] FindAll(OneWire bus)
        {
            if (bus == null)
                throw new ArgumentNullException("bus");

            var devices = new ArrayList();
            ArrayList presensePulses = bus.FindAllDevices();
            foreach (byte[] presensePulse in presensePulses)
            {
                if (presensePulse[0] != DS18S20FamilyCode
                    && presensePulse[0] != DS18B20FamilyCode)
                    continue;

                var device = new DS18X20(presensePulse, bus);
                devices.Add(device);
            }

            var result = (DS18X20[]) devices.ToArray(typeof (DS18X20));
            return result;
        }
Exemplo n.º 3
0
        public static void Main()
        {
            var op = new OutputPort(Stm32F4Discovery.FreePins.PA15, false);
            var ow = new OneWire(op);

            IDisplay display = new Display();

            DS18X20[] devices = DS18X20.FindAll(ow);
            if (devices.Length == 0)
            {
                display.ShowError("Brak DS18B20");
                return;
            }

            DS18X20 tempDev = devices[0];

            for (;;)
            {
                float  currentTemp  = 0;
                string exceptionMsg = String.Empty;
                try
                {
                    currentTemp = tempDev.GetTemperature();
                }
                catch (IOException ex)
                {
                    exceptionMsg = ex.Message;
                }

                if (exceptionMsg.Length == 0)
                {
                    display.ShowTemperature(currentTemp);
                }
                else
                {
                    display.ShowError(exceptionMsg);
                }

                Thread.Sleep(1000);
            }
        }