Unable to connect to ACR122U-A2 / ACR122U-A9

Bug #1257591 reported by Steven Githens
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
nfcpy
Fix Released
Medium
Stephen Tiedemann

Bug Description

Hi,

I've been having some issues connecting with the ACR122U-A2. I managed to get the Helloworld to sort of find it after pasting in the entire device ID, but then I get the error below.

Any ideas, or more diagnostics I can provide?

I'm on revno: 205.

Thanks so much!

examples/helloworld.py:
[snip]
57 def main(self):
58 with nfc.ContactlessFrontend('usb:072f:2200') as clf:
[snip]

 : lsusb
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 003 Device 032: ID 0424:2512 Standard Microsystems Corp. USB 2.0 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 147e:2020 Upek
Bus 001 Device 004: ID 04f2:b2ea Chicony Electronics Co., Ltd
Bus 003 Device 033: ID 0424:2602 Standard Microsystems Corp. USB 2.0 Hub
Bus 003 Device 034: ID 0424:2228 Standard Microsystems Corp. 9-in-2 Card Reader
Bus 003 Device 045: ID 072f:2200 Advanced Card Systems, Ltd
Bus 003 Device 036: ID 05ac:1006 Apple, Inc. Hub in Aluminum Keyboard
Bus 003 Device 037: ID 046d:c016 Logitech, Inc. Optical Wheel Mouse
Bus 003 Device 038: ID 05ac:024f Apple, Inc.
sgithens@sgithens-ThinkPad-X230:~/code/gpii-nfcpy/nfcpy$
 : sudo python examples/helloworld.py
INFO:nfc.clf:searching for reader with path 'usb:072f:2200'
Traceback (most recent call last):
  File "examples/helloworld.py", line 70, in <module>
    HelloWorld().main()
  File "examples/helloworld.py", line 58, in main
    with nfc.ContactlessFrontend('usb:072f:2200') as clf:
  File "/home/sgithens/code/gpii-nfcpy/nfcpy/nfc/clf.py", line 105, in __init__
    if path and not self.open(path):
  File "/home/sgithens/code/gpii-nfcpy/nfcpy/nfc/clf.py", line 156, in open
    self.dev = nfc.dev.connect(path)
  File "/home/sgithens/code/gpii-nfcpy/nfcpy/nfc/dev/__init__.py", line 64, in connect
    device = driver.init(usb)
  File "/home/sgithens/code/gpii-nfcpy/nfcpy/nfc/dev/acr122.py", line 92, in init
    chipset = Chipset(transport)
  File "/home/sgithens/code/gpii-nfcpy/nfcpy/nfc/dev/acr122.py", line 50, in __init__
    super(Chipset, self).__init__(transport)
  File "/home/sgithens/code/gpii-nfcpy/nfcpy/nfc/dev/pn53x.py", line 126, in __init__
    ic, ver, rev, support = self.get_firmware_version()
  File "/home/sgithens/code/gpii-nfcpy/nfcpy/nfc/dev/pn53x.py", line 243, in get_firmware_version
    else: ic, ver, rev, support = data
ValueError: too many values to unpack
sgithens@sgithens-ThinkPad-X230:~/code/gpii-nfcpy/nfcpy$

Revision history for this message
Stephen Tiedemann (stephen-tiedemann) wrote :

Please run "examples/tagtool.py -d nfc" and post the debug output.

Revision history for this message
Steven Githens (swgithen) wrote :

Hi Stephen,

Sorry for the lag in getting back to post this.

I think I actually have it working now, but will post again later today with my findings. (and/or close this ticket)

Thanks!
Steve

Revision history for this message
Steven Githens (swgithen) wrote :

Ok, so to follow up, a few odd notes:

1) In general I have to specify the full vendor string in connect methods, just 'usb' never seems to find the device.

2) It seems like my device has a hard time initializing or something. For instance, when I first plug it in and try it nothing happens and the LED stays off. But if I do the following it works:
  - Plug it in
  - sudo /etc/init.d/pcscd start
  - sudo /etc/init.d/pcscd stop
  - sudo 'whatever ncfpy code'

It feels like pcscd is initing or something, I've checked that pcscd is stopped before initially plugging the reader in.

I am attaching the output tagtool.py

Revision history for this message
Steven Githens (swgithen) wrote :
Revision history for this message
V Naresh (vnwarrior) wrote :

I'm getting the same issue. Interestingly however, when I use VirtualBox with a windowsXP VM, I dont face this issue !

[main] enable debug output for module 'nfc'
[nfc.clf] searching for reader with path 'usb'
[nfc.dev.transport] using pyusb version 1.x
[nfc.dev.transport] path matches '^(usb|)$'
[nfc.dev] trying usb:072f:2200
[nfc.dev] import nfc.dev.acr122
[nfc.dev.transport] >>> 6b050000000000000000ff00480000
[nfc.dev.transport] <<< 830a000000000002810041435231323255323133
[nfc.dev.acr122] GetFirmwareVersion called with timeout 100 ms
[nfc.dev.transport] >>> 6b070000000000000000ff00000002d402
[nfc.dev.transport] <<< 830a000000000002810041435231323255323133
Traceback (most recent call last):
  File "examples/tagtool.py", line 439, in <module>
    TagTool().run()
  File "/home/user/Downloads/shared/code/nfcpy/examples/cli.py", line 283, in run
    while self.run_once() and self.options.loop:
  File "/home/user/Downloads/shared/code/nfcpy/examples/cli.py", line 230, in run_once
    try: clf = nfc.ContactlessFrontend(device)
  File "/home/user/Downloads/shared/code/nfcpy/nfc/clf.py", line 105, in __init__
    if path and not self.open(path):
  File "/home/user/Downloads/shared/code/nfcpy/nfc/clf.py", line 156, in open
    self.dev = nfc.dev.connect(path)
  File "/home/user/Downloads/shared/code/nfcpy/nfc/dev/__init__.py", line 64, in connect
    device = driver.init(usb)
  File "/home/user/Downloads/shared/code/nfcpy/nfc/dev/acr122.py", line 92, in init
    chipset = Chipset(transport)
  File "/home/user/Downloads/shared/code/nfcpy/nfc/dev/acr122.py", line 50, in __init__
    super(Chipset, self).__init__(transport)
  File "/home/user/Downloads/shared/code/nfcpy/nfc/dev/pn53x.py", line 126, in __init__
    ic, ver, rev, support = self.get_firmware_version()
  File "/home/user/Downloads/shared/code/nfcpy/nfc/dev/pn53x.py", line 243, in get_firmware_version
    else: ic, ver, rev, support = data
ValueError: too many values to unpack

Revision history for this message
V Naresh (vnwarrior) wrote :

When all of the above is happening, the red LED on my device does NOT light up.

However - if I DONT blacklist pn533 , then the red LED lights up. Then I can do "modprobe -r pn533" and then all of nfcpy works perfectly.

I think there is an initialization step missing.

Revision history for this message
Stephen Tiedemann (stephen-tiedemann) wrote :

I can now confirm initialisation issues with an ACR122U213 (labelled ACR122U-A9).

Changed in nfcpy:
status: New → Confirmed
importance: Undecided → Medium
assignee: nobody → Stephen Tiedemann (stephen-tiedemann)
summary: - Unable to connect to ACR122U-A2
+ Unable to connect to ACR122U-A2 / ACR122U-A9
Revision history for this message
Steven Githens (swgithen) wrote :

Glad that folks can reproduce this. Let me know if there is anything I can do to help move this forward. I'm not sure if I have enough background knowledge to fix it, but if you can point me in the right direction in the code, I might be able to poke around a bit.

Cheers,
Steve

Revision history for this message
Stephen Tiedemann (stephen-tiedemann) wrote :

Fix committed and tested to work with an ACR122U-A9.

Changed in nfcpy:
status: Confirmed → Fix Released
Revision history for this message
Steven Githens (swgithen) wrote :

Thanks Stephen! I'll be trying this out tonight.

-Steve

Revision history for this message
Steven Githens (swgithen) wrote :

Awesome, things are working great with this fix. Thanks so much, I really appreciate your work on this project!

-Steve

Revision history for this message
Andrew Davison (andydvsn) wrote :

I'm afraid I'm still stuck here:

# python tagtool.py -d nfc
[main] enable debug output for module 'nfc'
[nfc.clf] searching for reader with path 'usb'
[nfc.dev.transport] using pyusb version 0.x
[nfc.dev.transport] path matches '^(usb|)$'
[nfc.dev] trying usb:072f:2200
[nfc.dev] import nfc.dev.acr122
[nfc.dev.transport] >>> 6f050000000000000000ff00480000
[nfc.dev.transport] <<< 800a000000000002810041435231323255323133
Traceback (most recent call last):
  File "tagtool.py", line 479, in <module>
    TagTool().run()
  File "/home/joggler/nfc/nfcpy/examples/cli.py", line 283, in run
    while self.run_once() and self.options.loop:
  File "/home/joggler/nfc/nfcpy/examples/cli.py", line 230, in run_once
    try: clf = nfc.ContactlessFrontend(device)
  File "/home/joggler/nfc/nfcpy/nfc/clf.py", line 105, in __init__
    if path and not self.open(path):
  File "/home/joggler/nfc/nfcpy/nfc/clf.py", line 156, in open
    self.dev = nfc.dev.connect(path)
  File "/home/joggler/nfc/nfcpy/nfc/dev/__init__.py", line 64, in connect
    device = driver.init(usb)
  File "/home/joggler/nfc/nfcpy/nfc/dev/acr122.py", line 121, in init
    chipset = Chipset(transport)
  File "/home/joggler/nfc/nfcpy/nfc/dev/acr122.py", line 40, in __init__
    reader_version = self.ccid_xfr_block(bytearray.fromhex("FF00480000"))
  File "/home/joggler/nfc/nfcpy/nfc/dev/acr122.py", line 81, in ccid_xfr_block
    if len(frame) != 10 + struct.unpack("<I", frame[1:5])[0]:
struct.error: unpack requires a string argument of length 4

Running as root for time being to test, but always the same result.

Revision history for this message
Stephen Tiedemann (stephen-tiedemann) wrote :

What is your python version? And could you check if the following works:

$ python
>>> import struct
>>> struct.unpack("<I", "\x0A\x00\x00\x00")
(10,)
>>> struct.unpack("<I", bytearray("\x0A\x00\x00\x00"))
(10,)

Revision history for this message
KasperA (spam-kma) wrote :

Hello everyone.

When running :

$ sudo python tagtool.py -d nfc, I get the follow dump

[main] enable debug output for module 'nfc'
[nfc.clf] searching for reader with path 'usb'
[nfc.dev.transport] using pyusb version 0.x
[nfc.dev.transport] path matches '^(usb|)$'
[nfc.dev] trying usb:072f:2200
[nfc.dev] import nfc.dev.acr122
[nfc.dev.transport] >>> 6f050000000000000000ff00480000
[nfc.dev.transport] <<< 800a000000000002810041435231323255323034
Traceback (most recent call last):
  File "tagtool.py", line 479, in <module>
    TagTool().run()
  File "/lhome/kasper/temp/pynfc/nfcpy/examples/cli.py", line 283, in run
    while self.run_once() and self.options.loop:
  File "/lhome/kasper/temp/pynfc/nfcpy/examples/cli.py", line 230, in run_once
    try: clf = nfc.ContactlessFrontend(device)
  File "/lhome/kasper/temp/pynfc/nfcpy/nfc/clf.py", line 105, in __init__
    if path and not self.open(path):
  File "/lhome/kasper/temp/pynfc/nfcpy/nfc/clf.py", line 156, in open
    self.dev = nfc.dev.connect(path)
  File "/lhome/kasper/temp/pynfc/nfcpy/nfc/dev/__init__.py", line 64, in connect
    device = driver.init(usb)
  File "/lhome/kasper/temp/pynfc/nfcpy/nfc/dev/acr122.py", line 121, in init
    chipset = Chipset(transport)
  File "/lhome/kasper/temp/pynfc/nfcpy/nfc/dev/acr122.py", line 40, in __init__
    reader_version = self.ccid_xfr_block(bytearray.fromhex("FF00480000"))
  File "/lhome/kasper/temp/pynfc/nfcpy/nfc/dev/acr122.py", line 81, in ccid_xfr_block
    if len(frame) != 10 + struct.unpack("<I", frame[1:5])[0]:
struct.error: unpack requires a string argument of length 4

I've tried the commands

Python 2.7.3 (default, Sep 26 2013, 20:03:06)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import struct
>>> struct.unpack("<I", "\x0A\x00\x00\x00")
(10,)
>>> struct.unpack("<I", bytearray("\x0A\x00\x00\x00"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
struct.error: unpack requires a string argument of length 4
>>>

So have I got a wrong python version ?

Thanks in advance

Revision history for this message
Stephen Tiedemann (stephen-tiedemann) wrote :

This is indeed an issue with the Python version. As this is different from the original bug I filed a new bug:1274973. and a fix will come in a minute or so.

Revision history for this message
casall (thorirtr) wrote :

I'm running into similar issues. I have the following:
 - Raspberry Pi
 - pyusb 1.0.0b2
 - Python 2.7.3 (default, Mar 18 2014, 05:13:23)
 - Using ACR-122U-A9 NFC reader

When running python check I get this:
>>> import struct
>>> struct.unpack("<I", "\x0A\x00\x00\x00")
(10,)
>>> struct.unpack("<I", bytearray("\x0A\x00\x00\x00"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
struct.error: unpack requires a string argument of length 4

Here is the output from tag tool.py

pi@bmipi1 ~/Downloads/nfcpy/examples $ sudo python tagtool.py -d nfc
[main] enable debug output for module 'nfc'
[nfc.clf] searching for reader with path 'usb'
[nfc.dev.transport] using pyusb version 1.x
[nfc.dev.transport] path matches '^(usb|)$'
[nfc.dev] trying usb:072f:2200
[nfc.dev] import nfc.dev.acr122
Traceback (most recent call last):
  File "tagtool.py", line 516, in <module>
    TagTool().run()
  File "/home/pi/Downloads/nfcpy/examples/cli.py", line 283, in run
    while self.run_once() and self.options.loop:
  File "/home/pi/Downloads/nfcpy/examples/cli.py", line 230, in run_once
    try: clf = nfc.ContactlessFrontend(device)
  File "/home/pi/Downloads/nfcpy/nfc/clf.py", line 105, in __init__
    if path and not self.open(path):
  File "/home/pi/Downloads/nfcpy/nfc/clf.py", line 156, in open
    self.dev = nfc.dev.connect(path)
  File "/home/pi/Downloads/nfcpy/nfc/dev/__init__.py", line 63, in connect
    usb = transport.USB(bus, dev)
  File "/home/pi/Downloads/nfcpy/nfc/dev/transport.py", line 207, in __init__
    self.open(bus_id, dev_id)
  File "/home/pi/Downloads/nfcpy/nfc/dev/transport.py", line 275, in _PYUSB1_open
    self.usb_out.write('')
  File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 349, in write
    return self.device.write(self, data, timeout)
  File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 870, in write
    intf, ep = self._ctx.setup_request(self, endpoint)
  File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 190, in setup_request
    self.managed_claim_interface(device, intf)
  File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 146, in managed_claim_interface
    self.backend.claim_interface(self.handle, i)
  File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 747, in claim_interface
    _check(self.lib.libusb_claim_interface(dev_handle.handle, intf))
  File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 552, in _check
    raise USBError(_strerror(ret), ret, _libusb_errno[ret])
  File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 541, in _strerror
    return _lib.libusb_strerror(errcode).decode('utf8')
  File "/usr/lib/python2.7/ctypes/__init__.py", line 378, in __getattr__
    func = self.__getitem__(name)
  File "/usr/lib/python2.7/ctypes/__init__.py", line 383, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
AttributeError: /lib/arm-linux-gnueabihf/libusb-1.0.so.0: undefined symbol: libusb_strerror

Is there an issue with the Python version?

Revision history for this message
Stephen Tiedemann (stephen-tiedemann) wrote :

This is not a Python version issue but related to libus/pyusb. The root cause seems to be that libusb fails to claim the interface for the USB device and returns some error code that the _check() method in pyusb wants to raise up the stack. Then conversion of the error code to an error string fails because the libusb dynamic library doesn't have the libusb_strerror function.

Without knowing what pyUSB wants to say about the problem with claim_interface, it's speculative to say what might have caused the issue first place. However, a common cause would be that some another process has already claimed it or there are insufficient access permissions.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.