Exemplo n.º 1
0
 ///<summary>
 /// Only when there is one slave on the bus
 ///</summary>
 public void ReadId()
 {
     lock (_port)
     {
         if (_port.InitializePort())
         {
             if (_port.Reset())
             {
                 this.WriteCommand(Command.ReadRom);
                 _id = this.Read(8);
             }
         }
     }
 }
Exemplo n.º 2
0
 ///<summary>
 /// Only when there is one slave on the bus
 ///</summary>
 public void ReadID()
 {
     lock (_port)
     {
         if (!_port.InitializePort())
         {
             return;
         }
         if (!_port.Reset())
         {
             return;
         }
         WriteCommand(Command.ReadROM);
         _ID = Read(8);
     }
 }
Exemplo n.º 3
0
        private void Run(byte selectedBit)
        {
            if (!port.Reset())
            {
                return;
            }
            if (!port.Write((byte)Command.SearchROM))
            {
                return;
            }
            for (var i = 0; i < 512; i++)
            {
                var ab = (byte)(port.ReadBit() == 0xFF ? 0x01 : 0x00);
                ab ^= (byte)(port.ReadBit() == 0xFF ? 0x02 : 0x00);
                if (ab != 0x00)
                {
                    if (ab == 0x01)
                    {
                        currentID[i] = 0xFF;
                    }
                    if (ab == 0x02)
                    {
                        currentID[i] = 0x00;
                    }
                    if (!port.WriteBit(currentID[i]))
                    {
                        return;
                    }
                }
                else
                {
                    done = lastDiscrepancy == i;
                    if (lastDiscrepancy == i)
                    {
                        switch (lastSelectedBit)
                        {
                        case 0x00:
                            selectedBit = 0xFF;
                            break;

                        case 0xFF:
                            selectedBit = 0x00;
                            break;
                        }
                    }
                    currentID[i]    = selectedBit;
                    lastDiscrepancy = i;
                    lastSelectedBit = selectedBit;
                    if (!port.WriteBit(selectedBit))
                    {
                        return;
                    }
                }
            }
        }
Exemplo n.º 4
0
        private void Run(byte selectedBit)
        {
            if (!_port.Reset())
            {
                return;
            }
            if (!_port.Write((byte)Command.SearchRom))
            {
                return;
            }
            byte ab = 0x00;

            for (int i = 0; i < 512; i++)
            {
                ab  = (byte)(_port.ReadBit() == 0xFF ? 0x01 : 0x00);
                ab ^= (byte)(_port.ReadBit() == 0xFF ? 0x02 : 0x00);

                /*if (ab == 0x03)
                 * throw new Exception("No any slaves found");*/
                if (ab != 0x00)
                {
                    if (ab == 0x01)
                    {
                        _currentId[i] = 0xFF;
                    }
                    if (ab == 0x02)
                    {
                        _currentId[i] = 0x00;
                    }
                    if (!_port.WriteBit(_currentId[i]))
                    {
                        return;
                    }
                }
                else
                {
                    if (_lastDiscrepancy != i)
                    {
                        _done = false;
                    }
                    else
                    {
                        _done = true;
                    }
                    if (_lastDiscrepancy == i)
                    {
                        if (_lastSelectedBit == 0x00)
                        {
                            selectedBit = 0xFF;
                        }
                        else if (_lastSelectedBit == 0xFF)
                        {
                            selectedBit = 0x00;
                        }
                    }
                    _currentId[i]    = selectedBit;
                    _lastDiscrepancy = i;
                    _lastSelectedBit = selectedBit;
                    if (!_port.WriteBit(selectedBit))
                    {
                        return;
                    }
                }
            }
        }