bool IdOnDemandReaderUnit::waitRemoval(unsigned int maxwait)
    {
        bool removed = false;

        if (d_insertedChip)
        {
            unsigned int currentWait = 0;
            do
            {
                std::shared_ptr<Chip> chip = getChipInAir();
                if (!chip)
                {
                    d_insertedChip.reset();
                    removed = true;
                }

                if (!removed)
                {
                    std::this_thread::sleep_for(std::chrono::milliseconds(100));
                    currentWait += 100;
                }
            } while (!removed && (maxwait == 0 || currentWait < maxwait));
        }

        return removed;
    }
	bool DeisterReaderUnit::waitInsertion(unsigned int maxwait)
	{
		bool inserted = false;
		unsigned int currentWait = 0;

		do
		{
			boost::shared_ptr<Chip> chip = getChipInAir();
			if (chip)
			{
				d_insertedChip = chip;
				inserted = true;
			}

			if (!inserted)
			{
#ifdef _WINDOWS
				Sleep(100);
#elif defined(__unix__)
				usleep(100000);
#endif
				currentWait += 100;
			}
		} while (!inserted && (maxwait == 0 || currentWait < maxwait));

		return inserted;
	}
 bool OK5553ReaderUnit::waitRemoval(unsigned int maxwait)
 {
     bool removed = false;
     removalIdentifier.clear();
     if (d_insertedChip)
     {
         unsigned int currentWait = 0;
         while (!removed && ((currentWait < maxwait) || maxwait == 0))
         {
             std::shared_ptr<Chip> chip = getChipInAir(250);
             if (chip)
             {
                 std::vector<unsigned char> tmpId = chip->getChipIdentifier();
                 if (tmpId != d_insertedChip->getChipIdentifier())
                 {
                     d_insertedChip.reset();
                     removalIdentifier = tmpId;
                     removed = true;
                 }
                 else
                 {
                     std::this_thread::sleep_for(std::chrono::milliseconds(100));
                     currentWait += 250;
                 }
             }
             else
             {
                 d_insertedChip.reset();
                 removed = true;
             }
         }
     }
     return removed;
 }
    bool AxessTMC13ReaderUnit::waitInsertion(unsigned int maxwait)
    {
        bool inserted = false;
        std::chrono::steady_clock::time_point const clock_timeout = std::chrono::steady_clock::now() + std::chrono::milliseconds(maxwait);

        if (d_tmcIdentifier.size() == 0)
        {
            retrieveReaderIdentifier();
        }

        do
        {
            std::shared_ptr<Chip> chip = getChipInAir();
            if (chip)
            {
                d_insertedChip = chip;
                inserted = true;
            }

            if (!inserted)
                std::this_thread::sleep_for(std::chrono::milliseconds(250));
        } while (!inserted && std::chrono::steady_clock::now() < clock_timeout);

        return inserted;
    }
    bool DeisterReaderUnit::waitRemoval(unsigned int maxwait)
    {
        bool removed = false;

        if (d_insertedChip)
        {
            std::chrono::steady_clock::time_point const clock_timeout = std::chrono::steady_clock::now() + std::chrono::milliseconds(maxwait);
            do
            {
				std::this_thread::sleep_for(std::chrono::milliseconds(1000)); //Deister 'forget' the card...
                std::shared_ptr<Chip> chip = getChipInAir();
                if (chip)
                {
                    if (chip->getChipIdentifier() != d_insertedChip->getChipIdentifier())
                    {
                        d_insertedChip.reset();
                        removed = true;
                    }
                }
                else
                {
                    d_insertedChip.reset();
                    removed = true;
                }

                if (!removed)
                    std::this_thread::sleep_for(std::chrono::milliseconds(250));
            } while (!removed && std::chrono::steady_clock::now() < clock_timeout);
        }

        return removed;
    }
    bool OK5553ReaderUnit::waitInsertion(unsigned int maxwait)
    {
        bool inserted = false;
        if (removalIdentifier.size() > 0)
        {
            d_insertedChip = createChip((d_card_type == "UNKNOWN") ? "GenericTag" : d_card_type);
            d_insertedChip->setChipIdentifier(removalIdentifier);
            removalIdentifier.clear();
            inserted = true;
        }
        else
        {
            std::shared_ptr<Chip> chip = getChipInAir(maxwait);
            if (chip)
            {
                d_insertedChip = chip;
                inserted = true;
            }
        }

        return inserted;
    }
    bool OK5553ReaderUnit::connect()
    {
        LOG(LogLevel::INFOS) << "Starting connect...";
        if (getSingleChip())
        {
            if (getSingleChip()->getCardType() == "DESFire")
            {
                std::vector<unsigned char> tmp = rats();
                if (tmp.size() == 0)
                {
                    d_insertedChip = getChipInAir();
                    tmp = rats();
                    if (tmp.size() == 0)
                    {
                        d_insertedChip.reset();
                    }
                }
            }
        }

        return bool(d_insertedChip);
    }
	bool DeisterReaderUnit::waitRemoval(unsigned int maxwait)
	{
		bool removed = false;
		unsigned int currentWait = 0;

		if (d_insertedChip)
		{
			do
			{
				boost::shared_ptr<Chip> chip = getChipInAir();
				if (chip)
				{
					if (chip->getChipIdentifier() != d_insertedChip->getChipIdentifier())
					{
						d_insertedChip.reset();
						removed = true;
					}
				}
				else
				{
					d_insertedChip.reset();
					removed = true;
				}

				if (!removed)
				{
	#ifdef _WINDOWS
					Sleep(100);
	#elif defined(__unix__)
					usleep(100000);
	#endif
					currentWait += 100;
				}
			} while (!removed && (maxwait == 0 || currentWait < maxwait));
		}

		return removed;
	}
    bool IdOnDemandReaderUnit::waitInsertion(unsigned int maxwait)
    {
        bool inserted = false;
        unsigned int currentWait = 0;

        do
        {
            std::shared_ptr<Chip> chip = getChipInAir();
            if (chip)
            {
                d_insertedChip = chip;
                inserted = true;
            }

            if (!inserted)
            {
                std::this_thread::sleep_for(std::chrono::milliseconds(100));
                currentWait += 100;
            }
        } while (!inserted && (maxwait == 0 || currentWait < maxwait));

        return inserted;
    }
    bool AxessTMC13ReaderUnit::waitRemoval(unsigned int maxwait)
    {
        bool removed = false;

        if (d_tmcIdentifier.size() == 0)
        {
            retrieveReaderIdentifier();
        }

        if (d_insertedChip)
        {
            std::chrono::steady_clock::time_point const clock_timeout = std::chrono::steady_clock::now() + std::chrono::milliseconds(maxwait);
            do
            {
                std::shared_ptr<Chip> chip = getChipInAir();
                if (chip)
                {
                    if (chip->getChipIdentifier() != d_insertedChip->getChipIdentifier())
                    {
                        d_insertedChip.reset();
                        removed = true;
                    }
                }
                else
                {
                    d_insertedChip.reset();
                    removed = true;
                }

                if (!removed)
                    std::this_thread::sleep_for(std::chrono::milliseconds(250));
            } while (!removed && std::chrono::steady_clock::now() < clock_timeout);
        }

        return removed;
    }