BarnabyShearer / pynfc

`ctypeslib` converted libnfc and libfreefare.
https://pynfc.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
16 stars 4 forks source link

when trying README example I get ArgumentError #2

Closed xetum closed 5 years ago

xetum commented 6 years ago

I get following error when I put the tag closer (an ISO/IEC 14443A (106 kbps) target):

Exception in thread Thread-2: Traceback (most recent call last): File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner self.run() File "/usr/lib/python2.7/threading.py", line 763, in run self.target(*self.args, *self.kwargs) File "/home/pi/.local/lib/python2.7/site-packages/pynfc/init__.py", line 37, in tread = threading.Thread(target=lambda: timeout_queue.put(func(args, **kwargs))) ArgumentError: argument 1: <type 'exceptions.TypeError'>: expected LP_nfc_device instance instead of LP_nfc_device

My script is (RPi3 device):

import pynfc
from pynfc import Nfc, Desfire, Timeout

n = Nfc("pn532_uart:/dev/ttyS0:115200")

DESFIRE_DEFAULT_KEY = b'\x00' * 8
MIFARE_BLANK_TOKEN = b'\xFF' * 1024 * 4

for target in n.poll(modulations=((pynfc.nfc.NMT_ISO14443A, pynfc.nfc.NBR_106),)):
    try:
        print(target.uid, target.auth(DESFIRE_DEFAULT_KEY if type(target) == Desfire else MIFARE_BLANK_TOKEN))
    except Timeout:
        pass

I suspect the problem is with get_tags (line 98 init.py). Thanks

xetum commented 5 years ago

The problem is that nfc_device definitions in freefare.py and nfc.py are different. in freefare.py add from .nfc import nfc_device and comment class nfc_device ... and nfc_device._fields_...

BarnabyShearer commented 5 years ago

Thank you for reporting, you were correct, and this should be fixed in the new 0.1.1 release.

xetum commented 5 years ago

just a question, if you want to install from git, pip3 install git+https://github.com/BarnabyShearer/pynfc.git won't execute gen.py. Does make need to be executed manually? (it could be executed automatically in python3 setup.py build)

BarnabyShearer commented 5 years ago

Yes atm, you would need to install the requirements.txt and then run make. You will also need your distro's version of sudo apt install -y libssl-dev libnfc-dev libfreefare-dev libclang-5.0-dev. I will look at replacing make with setup.py.