Exemplo n.º 1
0
        public static Device[] Scan(OneWire ow, params Family[] includeFamilies)
        {
            var addr = new byte[8];
            var list = new ArrayList();
            var all = false;
            var devs = ow.FindAllDevices();

            if (includeFamilies != null)
            {
                foreach (var f in includeFamilies)
                {
                    if (f == Family.Unknown)
                        all = true;
                }
            }

            foreach (byte[] da in devs)
            {
                if (includeFamilies == null || includeFamilies.Length == 0 || all)
                {
                    list.Add(new Device(da));
                }
                else
                {
                    foreach (var f in includeFamilies)
                    {
                        if (addr[0] == (byte)f)
                            list.Add(new Device(da));
                    }
                }
            }

            return (Device[])list.ToArray(typeof(Device));
        }
Exemplo n.º 2
0
        public DS18B20(Cpu.Pin pin, OneWireBus.Device dev)
        {
            m_op = new OutputPort(pin, false);
            m_ow = new OneWire(m_op);

            if (dev == null)
            {

                var x = m_ow.FindAllDevices();

                var devs = OneWireBus.Scan(m_ow, OneWireBus.Family.DS18B20);

                if (devs == null || devs.Length < 1)
                    throw new InvalidOperationException("No DS18B20 devices found on OneWire bus");

                dev = devs[0];
            }

            m_dev = dev;
        }
Exemplo n.º 3
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;
        }