1

I have recently implemented the Communication with ACR122 using the winscard library. I have used a timer to invoke all the relavant API Calls like 1. SCardEstablishContext 2. SCardListReaders etc to get the status of reader

I have kept the interval to five(5) seconds for the timer. So this make a delay of 5 seconds in getting device status.

Can anyone suggest me a better approach like "event based trigger" to avoid this delay and remove timer all together.

Michael Roland
  • 39,663
  • 10
  • 99
  • 206
hellowahab
  • 2,445
  • 4
  • 21
  • 34

1 Answers1

0

Below is the general approach I have followed in the couple of projects I have implemented. Hope it

helps.

1) Initialize all the readers that are connected to the system (using the apis like

SCardEstablishContext and SCardListReaders)

2) Start polling for card on each of the readers from a thread (using the apis like

SCardGetStatusChange ). I would have one thread for each reader. When the reader detects a card

placed on it raise an event to do card transactions.

3)Handle the event raised by the polling thread to make card transactions (using apis like

SCardConnect SCardTransmit used)

I think the above approach will help you get rid of timers and optimize performance.

Vinayak Bhat
  • 341
  • 3
  • 7
  • How is that better? Now you have x threads devoted to polling, each using a devoted stack (taking up memory), giving something to the GC to process, potentially causing context switches, using CPU, potentially taking CPU away from processing that could use it more effectively, etc. Frankly, a timer sounds like a better idea. – Peter Ritchie Sep 16 '14 at 10:37
  • @PeterRitchie: Little bit of background on as to why thread based solution was used & suggested:- SCardGetStatusChange is a blocking call. we can in set it in such a way that it will return only when the card is placed on the reader. So that the real polling for card is done by the smart card reader (which has a microcontroller) and the calling thread is idle. – Vinayak Bhat Sep 16 '14 at 13:41