fabienrousseau/flutter_pcsc

Reader gets stuck when waitForCardPresent or waitForCardRemoved used

Opened this issue · 0 comments

When using waitForCardPresent and waitForCardRemoved to detect the card automatically in a program, the reader gets stuck and can't do more than 5 operations. After 3-5 operations, it just locks up. Even when waiting in a different isolate, this issue still occurs. For example, if I wait for a card to be present, read 5-6 values, the program just halts and waits until the card is removed and then throws an exception about how it couldn't read the card because there is no card in there. But I can see that the waitForCardPresent ends and it detects the card. Issue only occurs after a few operations are made.

What is more interesting is that the code works in debug mode and doesn't work in production mode. I believe it might be caused by library bindings to the winscard.h (or maybe some compile options?). I tried to run a similar code in C while using the library winscard.h, and everything works fine there. Here is an overview of what I am doing:

I'm using Ubuntu Linux 22.04.3 LTS, but similar error occurs in the MAC OS version as well.

while (true) {
      //Wait for a new card
      await Pcsc.waitForCardPresent(readerContext, readerName);
      final currentCard = await Pcsc.cardConnect(readerContext, readerName, PcscShare.shared, PcscProtocol.any);
      final cardNUID = await _getCardNUID(currentCard);
      sendPort.send(PcscCardInfo(currentCard, cardNUID.data)); //Communicate the message to outside of the isolate
      
      //Wait for the current card to be removed
      await Pcsc.waitForCardRemoved(readerContext, readerName);
      sendPort.send(null); //Communicate the message to outside of the isolate
    }

It works in an islotate on its own, and I've tried various different versions of this code. After calling any of the waitFor command, no other operation is possible. (After a few operations at first)