Inheritance: IDisposable
示例#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);
        }
示例#2
0
        void ResetOneWireAndMatchDeviceRomAddress()
        {
            DS2482_100.OneWireReset();

            DS2482_100.OneWireWriteByte(RomCommand.MATCH);

            foreach (var item in OneWireAddress)
            {
                DS2482_100.OneWireWriteByte(item);
            }
        }
示例#3
0
        protected byte[] GetTemperatureScratchpad()
        {
            ResetOneWireAndMatchDeviceRomAddress();
            DS2482_100.EnableStrongPullup();
            StartTemperatureConversion();

            ResetOneWireAndMatchDeviceRomAddress();

            var scratchpad = ReadScratchpad();

            return(scratchpad);
        }
示例#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);
        }
示例#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);
        }
示例#6
0
        void StartTemperatureConversion()
        {
            DS2482_100.OneWireWriteByte(FunctionCommand.CONVERT_T);

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