Beispiel #1
0
 public void SetSensorAddress(DS18B20_Address Address)
 {
     byte[] b = Address;
     Array.Reverse(b); //Muss umgekehrt in den Buffer;
     for (byte ix = 0; ix < 8; ix++)
     {
         ByteToBuffer(b[ix], (byte)(ix + 1));
     }
 }
Beispiel #2
0
 public void SetSensorAddress(string stringAD)
 {
     //DS18B20_Address Ad =
     byte[] b = new DS18B20_Address(stringAD);
     Array.Reverse(b); //Muss umgekehrt in den Buffer;
     for (byte ix = 0; ix < 8; ix++)
     {
         ByteToBuffer(b[ix], (byte)(ix + 1));
     }
 }
Beispiel #3
0
        /// <summary>
        /// Sucht Bus nach Sensoren
        /// </summary>
        /// <param name="Address">Referenz auf Byte Array, gibt Adresse zurück</param>
        /// <returns>Letzter sensor = false</returns>
        //public bool Search(ref byte[] Address)
        public bool Search(ref DS18B20_Address Address)
        {
            if (LastDevice || Devices < 1)
            {
                return(true);
            }


            ByteToBuffer(Command.Search);
            //Send Command
            //WriteCommandToPort(8);
            WriteToPort(8);
            System.Threading.Thread.Sleep(5);

            //Clear Data Buffer(+8) from last Conflict
            for (int ix = Bit_last_Conflict_pos + 1 + 8; ix < 8 * 8; ix++)
            {
                Buffer[ix] = 0x0;
            }

            for (byte BitsPos = 0; BitsPos < 8 * 8; BitsPos++)
            {
                ByteToBuffer(3); //0b00000011

                //Get Payload
                //WriteCommandToPort(2);
                WriteToPort(2);


                switch (BufferToBytes(0, 1)[0])
                {
                case 0:
                    //Konflikt 2 mögliche Pfade wähle erst 0 dann beim nächtsetn mal 1
                    if (Buffer[BitsPos + 8] == 0x00)
                    {
                        Bit_last_Conflict_pos = BitsPos;
                    }
                    break;

                case 1:
                    //Antwort Write 1
                    SetBufferDataBit(BitsPos, Bit.HIGH);
                    break;


                case 2:
                    //Antwort Write 0
                    SetBufferDataBit(BitsPos, Bit.LOW);
                    break;

                case 3:
                    //Fehler ToDo...
                    break;
                }
                //Im Datenbuffer ist das nächste Kommando enthalen
                Buffer[0] = Buffer[BitsPos + 8];
                //WriteCommandToPort(1);
                WriteToPort(1);
            }

            //aktuelles Ergebniss speichern
            //Address = BufferToBytes(8,8);
            Address = GetSensorAddress();

            //Pfad,Buffer für nächsten Durchlauf vorbereiten
            if (Buffer[Bit_last_Conflict_pos + 8] != 0xFF && Bit_last_Conflict_pos != 0)
            {
                SetBufferDataBit(Bit_last_Conflict_pos, Bit.HIGH);
                Devices++;
                LastDevice = false;
            }
            else
            {
                LastDevice = true;
            }


            return(false);
        }
Beispiel #4
0
 public DS18B20_Address(DS18B20_Address ad)
 {
     CRC          = ad.CRC;
     SerialNumber = (byte[])ad.SerialNumber.Clone();
     FamilyCode   = ad.FamilyCode;
 }