Nfc service ocassionaly stops working upon receiving error during card reading

Forum / MIFARE general topics and applications / Nfc service ocassionaly stops working upon receiving error during card reading

  • 3. November 2020 at 14:31
    Hi

    Im working on Inspection application which reads MifareUL and MifareClssic cards.
    Issue im having is that occasionaly NFC service stops working and taping card does nothing after this point (no new events are received).
    After this, it is required to disable and enable NFC service again in order to make NFC work.
    Device im using is Bluebird EF501. It runs Android 7.1.2.

    Reader is enabled like this:
    `
    val flags = NfcAdapter.FLAG_READER_NFC_A or NfcAdapter.FLAG_READER_NFC_B or
    NfcAdapter.FLAG_READER_NFC_F or NfcAdapter.FLAG_READER_NFC_V or
    NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK

    try {
    nxpNfcInstance.enableReaderMode(1000, {
    handleTag(it)
    }, flags)
    } catch (e: Exception) {
    Timber.e(e, "Failed to enable reader mode!")
    }
    `

    after decoding what kind of media it is and obtaining ICard object card data are read like this:
    `
    return withContext(Dispatchers.IO) {
    try {
    classic.reader.connect()
    classic.reader.timeout = CARD_READ_TIMEOUT

    val sectorList = IntRange(0, CLASSIC_SECTOR_COUNT - 1)
    .asSequence()
    .onEach { s -> authenticateSector(s, classic) }
    .map { s ->
    readBlocksFromSector(s, classic).let { blocks -> ... }
    }
    .toList()

    MifareClassicData(sector = sectorList, uid = uid)
    } finally {
    classic.reader.close()
    }
    }

    private fun readBlocksFromSector(sector: Int, classic: IMFClassic): Array {
    val startBlock = classic.sectorToBlock(sector)
    return Array(3) { index ->
    classic.readBlock(startBlock + index)
    }
    }
    `

    threading is like this:
    Binder thread
    event is sent media processing component
    Main thread
    decoded media type from tag
    obtained ICard object
    Dispatchers.IO thread
    reading of card data
    Main thread
    data processed


    Do you have any experience with such issues?
    Idont know what im doning wrong, what can cause this issue and it is starting to be quit problem.
    Also on other device it seems to not happening but im not sure if this is case.

    Thansk for helpnig
    Michal
    + 0  |  - 0

    Re: Nfc service ocassionaly stops working upon receiving error during card reading

    3. November 2020 at 14:46
    This post was sent twice.
    It is answered in the first.

    + 0  |  - 0
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.