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);
            }
        }
Beispiel #2
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));
        }
 private bool PreInit(object sender, EventArgs e)
 {
     BlinkingLed = new SignalGenerator(EMX.Pin.IO17, false, 2);
     Blink(100);
     OneWireBus = new OneWire(new OutputPort(EMX.Pin.IO26, false));
     return true;
 }
		public Ds18B20(OneWire ow, OneWireBus.Device dev)
		{
			m_ow = ow;
			if (dev == null)
			{
				var devs = OneWireBus.Scan(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;
		}
		public Ds18B20(Cpu.Pin pin, OneWireBus.Device dev)
		{
			m_op = new OutputPort(pin, false);
			m_ow = new OneWire(m_op);
			if (dev == null)
			{
				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;
		}
 /// <summary>
 /// Constructs DS-18B20 object for a given 1-wire bus and a device sequence number. 
 /// </summary>
 /// <param name="bus">1-wire bus to whish the sensor is attached</param>
 /// <param name="index">sequence index of a bus element</param>
 public Ds18b20(OneWire bus, int index)
 {
     if (bus.AcquireEx() < 0)
     {
         throw new InvalidOperationException("Invalid OneWire bus.");
     }
     OneWireBus = bus;
     ArrayList devices = GetDevices();
     if (index >= devices.Count)
     {
         throw new IndexOutOfRangeException("Invalid device number.");
     }
     Address = (byte[])devices[index];
 }
Beispiel #7
0
        private DS18X20(byte[] presensePulse, OneWire bus)
        {
            if (presensePulse == null)
                throw new ArgumentNullException("presensePulse");

            if (bus == null)
                throw new ArgumentNullException("bus");

            if (presensePulse[0] != DS18S20FamilyCode
                && presensePulse[0] != DS18B20FamilyCode)
                throw new ArgumentException("Wrong pulses", "presensePulse");

            _presensePulse = presensePulse;
            _bus = bus;

            _sSeries = _presensePulse[0] == DS18S20FamilyCode;
        }
 /// <summary>
 /// Constructs DS-18B20 object for a given 1-wire bus and a device address
 /// </summary>
 /// <param name="bus">1-wire bus to whish the sensor is attached</param>
 /// <param name="address">device address</param>
 public Ds18b20(OneWire bus, byte[] address)
 {
     if (bus.AcquireEx() < 0)
     {
         throw new InvalidOperationException("Invalid OneWire bus.");
     }
     OneWireBus = bus;
     ArrayList devices = GetDevices();
     foreach (byte[] Address in devices)
     {
         if (Address.Compare(address))
         {
             this.Address = Address;
             return;
         }
     }
     throw new InvalidOperationException("Device with the specified address is not present in the bus.");
 }
Beispiel #9
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;
        }
		public Ds18B20(OneWire ow) : this(ow, null) {}
Beispiel #11
0
        private void InitBus()
        {
            //var socket = Socket.GetSocket(12, true, null, null);
            //var i2c = new I2CBus(socket, 1, busClockRate, null);

            //byte[] b = new byte[5];
            //int i = i2c.Read(b, 1000);
            //Debug.Print(b[0].ToString() + i);

            //byte[] b = new byte[1];
            //int i = i2c.WriteRead(new byte[] {0x00}, b, 1000);
            //Debug.Print(b[0].ToString() + i);
            //- See more at: https://www.ghielectronics.com/community/forum/topic?id=13503&page=2#msg137894


            //networkCoordinator = new NetworkCoordinator();

            //busHubI2C = new BusHubI2C(new BusConfiguration(new I2CDevice(null)));
            //busHubI2C.BusModulesCollectionChanged += busHubI2C_BusModulesCollectionChanged;
            //networkCoordinator.BusHubs.Add(busHubI2C);

            //----------------------------------------------------------
            OneWire ow = new OneWire(new OutputPort(Socket.GetSocket(11, true, null, null).CpuPins[3], false));
            busHubOneWire = new BusMasterOneWire(ow);
            busHubOneWire.BusModulesCollectionChanged += busHub_BusModulesCollectionChanged;
            //OneWireExtension.Device[] devs = OneWireExtension.Scan(Socket.GetSocket(11, true, null, null).CpuPins[3]);
            //var b = devs;

        }
 public BusMasterOneWire(OneWire bus)
     : base(0)
 {
     this.bus = bus;
 }
Beispiel #13
0
        public M8_TempMgr(Cpu.Pin owPin)
        {
            this._owPin = owPin;
            this._owBus = new OneWire(this._owPin);

            this._thermometers = new ArrayList();
            this._getThermometers();
        }