Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CardMonitoring: cards can be seen multiple times #30

Conversation

lburg
Copy link

@lburg lburg commented Oct 4, 2016

Add a newcardonly argument to CardMonitor and CardMonitoringThread so that observers can get notified several times about the same card. Defaults to the current implementation of not notifying several times.

I need to check that a RFID reader keeps working under certain conditions (temperature, magnetic field, etc.), and it's not convenient (if not dangerous) to have a human perform these tasks. Thus the need for continuous notifications to detect if the reader stops working.

Is it something you can see go in the core of pyscard?

Also, I modified some tests but couldn't get them to run. How can I get them to run? I tried simply calling python path/to/testcase_CardMonitor.py but had errors when importing local_config, then I had error importing configcheck when trying to run the test suite. I also tried with the python -m smartcard.test.testcase_CardMonitor syntax but to no avail. I didn't find any doc around running tests either.

Thanks!

Add a newcardonly argument to CardMonitor and CardMonitoringThread so
that observers can get notified several times about the same card.
Defaults to the current implementation of *not* notifying several times.
@coveralls
Copy link

coveralls commented Oct 4, 2016

Coverage Status

Coverage decreased (-0.03%) to 23.947% when pulling a8ffd01 on lburg:lburg/notify_continuous_card_detection into 7776e55 on LudovicRousseau:master.

@LudovicRousseau
Copy link
Owner

I am not sure you can easily run a single test.
To run the framework test suite use:

cd smartcard/test/framework
python testsuite_framework.py

@LudovicRousseau
Copy link
Owner

I am not familiar with CardMonitor and CardMonitoringThread.
Can you describe what you get now and what you want to get instead?

@lburg
Copy link
Author

lburg commented Oct 5, 2016

With the current implementation if I keep a RFID card close to the reader I only get notified once, i.e. notifyObservers is called once, and so is the update(self, observable, actions) function from my custom Observer. What I'd like is for this function to be called several times as long as the reader sees the card.

The CardMonitoringThread class keeps track of the list of cards it's already seen (the cards attribute) and only notifies observers when the card read is not in this list. The newcardonly argument I introduce disables this tracking when set to False (defaults to True), making CardMonitoringThread always think the card is new and notify all observers.

Thanks for the help on running the tests, I'll get them working :)

@LudovicRousseau
Copy link
Owner

Is the program also notified when the card is "removed"?

When setting newcardonly to False, it was impossible to know if a card
was removed or not, thus observers weren't notified.
@coveralls
Copy link

coveralls commented Oct 5, 2016

Coverage Status

Coverage decreased (-0.02%) to 23.956% when pulling 6b262f0 on lburg:lburg/notify_continuous_card_detection into 7776e55 on LudovicRousseau:master.

@lburg
Copy link
Author

lburg commented Oct 5, 2016

Nice catch, I juste fixed that behaviour!

Regarding the tests, whenever I try to run them I get an error :

» python testsuite_framework.py
regenerating local_config.py...
Traceback (most recent call last):
  File "testsuite_framework.py", line 59, in <module>
    configcheck.checklocalconfig()
  File "../configcheck.py", line 62, in checklocalconfig
    expectedATRs.append(getATR(reader))
  File "../configcheck.py", line 38, in getATR
    cc.connect()
  File "/home/lburg/dev/pyscard/smartcard/CardConnectionDecorator.py", line 54, in connect
    self.component.connect(protocol, mode, disposition)
  File "/home/lburg/dev/pyscard/smartcard/pcsc/PCSCCardConnection.py", line 128, in connect
    SCardGetErrorMessage(hresult))
smartcard.Exceptions.CardConnectionException: Unable to connect with protocol: T0 or T1. Card is unpowered.

The reader is powered on and the pcsc service is running, do I need some kind of smartcard to be able to run tests?

@LudovicRousseau
Copy link
Owner

Maybe you should debug your code and run the test suite using a normal (contact) reader.

Note that I will not accept your first patch with the newcardonly parameter. A card event should be notified once. Otherwise it is not an event.

@lburg
Copy link
Author

lburg commented Oct 6, 2016

Alright, I can understand that. We'll replicate this behaviour from our software then, I'm closing this PR :)

Thank you for your help!

@lburg lburg closed this Oct 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants