Inheritance: IDisposable
Ejemplo n.º 1
0
        /// <summary>
        /// One wire device handler via DS2482-100
        /// </summary>
        /// <param name="ad0">AD0 addess bit</param>
        /// <param name="ad1">AD1 addess bit</param>
        /// <exception cref="Rinsen.IoT.OneWire.DS2482100DeviceNotFoundException">Thrown if no DS2482-100 device is detected</exception>
        public OneWireDeviceHandler(bool ad0 = true, bool ad1 = true)
        {
            byte address = 0x18;

            if (ad0)
            {
                address |= 1 << 0;
            }
            if (ad1)
            {
                address |= 1 << 1;
            }

            _ds2482_100 = new DS2482_100(new I2cDeviceLocator().GetI2cDevice(address));

            try
            {
                _ds2482_100.OneWireReset();
            }
            catch (Exception e)
            {
                throw new DS2482100DeviceNotFoundException("No DS2482-100 detected, check that AD0 and AD1 is correct in ctor and that the physical connection to the DS2482-100 one wire bridge is correct.", e);
            }

            _oneWireDeviceTypes = new Dictionary <byte, Type>();

            AddDeviceType <DS18S20>(0x10);
            AddDeviceType <DS18B20>(0x28);
        }
Ejemplo n.º 2
0
        void ResetOneWireAndMatchDeviceRomAddress()
        {
            DS2482_100.OneWireReset();

            DS2482_100.OneWireWriteByte(RomCommand.MATCH);

            foreach (var item in OneWireAddress)
            {
                DS2482_100.OneWireWriteByte(item);
            }
        }
Ejemplo n.º 3
0
        protected byte[] GetTemperatureScratchpad()
        {
            ResetOneWireAndMatchDeviceRomAddress();
            DS2482_100.EnableStrongPullup();
            StartTemperatureConversion();

            ResetOneWireAndMatchDeviceRomAddress();

            var scratchpad = ReadScratchpad();

            return(scratchpad);
        }
Ejemplo n.º 4
0
        byte[] ReadScratchpad()
        {
            DS2482_100.OneWireWriteByte(FunctionCommand.READ_SCRATCHPAD);

            var scratchpadData = new byte[9];

            for (int i = 0; i < scratchpadData.Length; i++)
            {
                scratchpadData[i] = DS2482_100.OneWireReadByte();
            }

            return(scratchpadData);
        }
Ejemplo n.º 5
0
        private static DS2482_100 PrivateCreateDs2482_100(I2cDevice i2cDevice, bool disposeI2cDevice)
        {
            var ds2482_100 = new DS2482_100(i2cDevice, disposeI2cDevice);

            try
            {
                ds2482_100.OneWireReset();
            }
            catch (Exception e)
            {
                throw new DS2482100DeviceNotFoundException("No DS2482-100 detected, check that AD0 and AD1 is correct in ctor and that the physical connection to the DS2482-100 one wire bridge is correct.", e);
            }

            return(ds2482_100);
        }
Ejemplo n.º 6
0
        void StartTemperatureConversion()
        {
            DS2482_100.OneWireWriteByte(FunctionCommand.CONVERT_T);

            Task.Delay(TimeSpan.FromSeconds(1)).Wait();
        }