Ejemplo n.º 1
0
        /// <summary>
        /// Initialize the sensor. This step will perform a reset of the 1-wire bus.
        /// It will check for existence of a 1-wire device. If no address was provided, then the
        /// 1-wire bus will be searched and the first device that matches the family code will be latched on to.
        /// Developer should check for successful initialization by checking the Address property.
        /// It should have valid 64-bit value
        /// </summary>
        public override void Initialize()
        {
            bool found = true;

            if (Address == null) //search for a device with the required family code
            {
                found = false;
                if (_oneWire.FindFirstDevice(true, false)) //Current nF firmware works if reset if performed before a find operation
                {
                    do
                    {
                        if (_oneWire.SerialNumber[0] == FAMILY_CODE)
                        {
                            //found the device
                            Address = new byte[_oneWire.SerialNumber.Length];
                            Array.Copy(_oneWire.SerialNumber, Address, _oneWire.SerialNumber.Length);
                            found = true;
                            break;
                        }
                    } while (_oneWire.FindNextDevice(true, false));//keep searching until we get one
                }
            }
            if (!found)
            {
                throw new Exception();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initialize the sensor. This step will perform a reset of the 1-wire bus.
        /// It will check for existence of a 1-wire device. If no address was provided, then the
        /// 1-wire bus will be searched and the first device that matches the family code will be latched on to.
        /// Developer should check for successful initialization by checking the value returned.
        /// It must be bigger than 0.
        /// If in Multidrop mode will keep seaching until find last device, saving all in AddressNet array.
        /// </summary>
        public bool Initialize()
        {
            Found = 0;
            //ArrayList allDevices;
            ArrayList allDevices = new ArrayList();

            _oneWire.TouchReset();

            if (Address == null) //search for a device with the required family code
            {
                //found the device
                if (Multidrop)
                {
                    if (_oneWire.FindFirstDevice(false, searchMode))
                    {
                        do
                        {
                            if (_oneWire.SerialNumber[0] == FAMILY_CODE)
                            {
                                _oneWire.TouchReset();
                                Address = new byte[_oneWire.SerialNumber.Length];
                                Array.Copy(_oneWire.SerialNumber, Address, _oneWire.SerialNumber.Length);
                                Found++;
                                allDevices.Add(Address);
                                //if (Found == 6) { break; } //Temp fix during test endless loop
                            }
                        } while (_oneWire.FindNextDevice(false, searchMode));//keep searching until we get one
                    }

                    if (Found > 0)
                    {
                        AddressNet = new byte[Found][];
                        int i = 0;
                        foreach (byte[] device in allDevices)
                        {
                            AddressNet[i] = new byte[device.Length];
                            Array.Copy(device, AddressNet[i], device.Length);
                            i++;
                        }
                        allDevices = null;
                    }
                }
                else
                {
                    if (_oneWire.FindFirstDevice(true, searchMode))
                    {
                        do
                        {
                            if (_oneWire.SerialNumber[0] == FAMILY_CODE)
                            {
                                Address = new byte[_oneWire.SerialNumber.Length];
                                Array.Copy(_oneWire.SerialNumber, Address, _oneWire.SerialNumber.Length);
                                Found = 1;
                                break;
                            }
                        } while (_oneWire.FindNextDevice(true, searchMode));//keep searching until we get one
                    }
                }
            }
            if (Found > 0)
            {
                return(true);
            }
            ;
            return(false);
        }