NFCpy throwing error in demo helloworld.py with Arygone reader on linux system

Asked by guitar_dude

I have an arygon reader on a ubuntu box.
cp210x loads and the reader is attached to ttyUSB0

when I try to run hell world sample, the following happens:

Traceback (most recent call last):
  File "helloworld.py", line 68, in <module>
    main()
  File "helloworld.py", line 35, in main
    clf = nfc.ContactlessFrontend()
  File "/home/earlence/nfcwork/nfcpy/nfc/clf.py", line 46, in __init__
    try: self.dev = device()
  File "/home/earlence/nfcwork/nfcpy/nfc/dev/pn53x.py", line 462, in __init__
    self.dev = pn53x.search()
  File "/home/earlence/nfcwork/nfcpy/nfc/dev/pn53x.py", line 126, in search
    try: return pn53x_tty(name)
  File "/home/earlence/nfcwork/nfcpy/nfc/dev/pn53x.py", line 426, in __init__
    ic, ver, rev, support = self.get_firmware_version()
  File "/home/earlence/nfcwork/nfcpy/nfc/dev/pn53x.py", line 209, in get_firmware_version
    rsp = self.command(0x02)
  File "/home/earlence/nfcwork/nfcpy/nfc/dev/pn53x.py", line 158, in command
    self.write(frame)
  File "/home/earlence/nfcwork/nfcpy/nfc/dev/pn53x.py", line 444, in write
    if self.tty.write(frame) != len(frame):
  File "/usr/lib/python2.6/dist-packages/serial/serialposix.py", line 330, in write
    raise TypeError('expected str, got %s' % type(data))
TypeError: expected str, got <type 'array.array'>

My python version is 2.6.6

-Earlence

Question information

Language:
English Edit question
Status:
Solved
For:
nfcpy Edit question
Assignee:
No assignee Edit question
Solved by:
guitar_dude
Solved:
Last query:
Last reply:

This question was reopened

Revision history for this message
Stephen Tiedemann (stephen-tiedemann) said :
#1

This looks like a problem with the version of python-serial, the version 2.5 that ships with Ubuntu 11.04 accepts and converts the array type. Anyhow, I've changed the code to make the conversion explicitly (with rev #94) and this should get you at least further.

Btw, did you had to change anything else to get your Arygon reader working? And could you provide more information on which sort of Arygon reader you're using, there seem to be some flavors around (I've got an older one with just 9600 kbps serial speed over USB which I regarded as just too slow for being worth to think about. And the I've got a Stollmann branded reader which looks pretty similar to the Arygon but runs 115200 kbps USB serial and directly connects to the PN53x serial interface - this is actually the one I've used for the pn53x_tty driver part).

/Stephen

Revision history for this message
guitar_dude (earlenceferns) said :
#2

Hello,

I have just tried the latest dev version and this is what I get:

AttributeError: 'Serial' object has no attribute 'name'

My Arygon Reader iV6.5 - PN532 v1.6
I havent changed anything yet anywhere. Im just trying to get started.

I am trying nfcpy mainly bcoz of an issue I am facing with libnfc. from the Nexus S, if I try to send a 59 bytepacket, it fails. I read that this is some kind of AGF-frame bug that was fixed in 2.3.4 and I am using 2.3.4!

-Earlence

Revision history for this message
Stephen Tiedemann (stephen-tiedemann) said :
#3

Again something that is only in pyserial >= 2.5, which as the Ubuntu package logs say is only shipped since Natty Narwhal. Could you try with the branch https://code.launchpad.net/~stephen-tiedemann/nfcpy/test-pyserial-old-version where I've added a few things to (hopefully) make the older version work.

bzr branch lp:~stephen-tiedemann/nfcpy/test-pyserial-old-version

Btw, the helloworld example, if working at last, will overwrite your NDEF data. Better use tagtool.py to avoid that.

Revision history for this message
guitar_dude (earlenceferns) said :
#4

Thank you. I will try it.

Revision history for this message
Stephen Tiedemann (stephen-tiedemann) said :
#5

Earlence,

I just remembered that your problem with sending more than 59 bytes sounds familiar to me and is probably the same as I described in https://launchpad.net/nfcpy/+announcement/8540. If that is the case, the only workaround I know of is to (a) force the reader to become Initiator or (b) use a Sony RC-S330/360 which didn't show that limitation when running against a Nexus S.

/Stephen

PS: Would still be nice to hear if the modified nfcpy works with your Arygon reader.

Revision history for this message
guitar_dude (earlenceferns) said :
#6

Yes, I think it is a problem of AGF-frames not being supported which causes the IOException. In any case, I need bidirectional communication between the Nexus S and the reader. I hope there is some workaround, otherwise, I will have to modify the android sources to use the underlying NFC-DEP directly.

Yes, nfcpy started working, but it cannot detect the reader which is attached to ttyUSB0. I suspect it is not using serial communications to access it, but USB. I was reading an earlier thread here that concerned arygon. I will try to see if I can get anything working.

cheers,
Earlence

Revision history for this message
Stephen Tiedemann (stephen-tiedemann) said :
#7

I don't think the problem is related to PDU aggregation, (i) it shows up with an SCL 3711 even if use of AGF is switched off (--quirks android), (ii) there is no problem when using an RC-S330/360 and (iii) it would mean that your code is actively generating AGF PDUs (as far as I've seen the libnfc-llcp code does not yet do it automatically).

As for serial communication, nfcpy is actually using serial over USB and works pretty well with a Stollmann reader (http://www.stollmann.de/fileadmin/01_Content/pdf/NFCEvaDev_Matrix_en_r03_01.pdf). Arygon readers, afaik, use a lower communication speed - just 9600 baud - and connect an MCU and not directly the PN53x. With the Arygon I have (slightly older model) I was able to get some sensible output with the following code:

import serial

tty = serial.Serial("/dev/ttyUSB0", 9600, 8, "N", 1)
tty.write("0ar")
print tty.read(10)
tty.write("0av")
print tty.read(16)

tty.write("2" + "0000ff02fed4022a00".decode("hex"))
print tty.read(17).encode("hex")
# answer: 0000ff00ff000000ff04fcd50304022200

Revision history for this message
guitar_dude (earlenceferns) said :
#8

yes, that piece of code detects my reader.
so, I changed pn53x_tty in pn53x.py to use a baud of 9600, however, it still does not detect it at ttyUSB0 (I have verified that cp201x attaches to this) and moves on to the code to check the USB ports. This is strange.

AGF-Frames - if that is the case, then simply using nfcpy should solve my problem, right?

-Earlence

Revision history for this message
Stephen Tiedemann (stephen-tiedemann) said :
#9

No surprise, there needs more to be changed. The Arygon reader requires a protocol mode byte at the beginning of every command, which is "2" for plain TAM commands.

I just found that the serial communication speed can be set to higher values and this makes the reader again more interesting. Likely that I'll push a new development branch out shortly and although my reader reports version 3.2 I guess that'll work with yours as well.

Unfortunately I do not expect that to solve your original problem with sending larger NDEF messages from Nexus S (in the specific case that the Nexus is the DEP Initiator). The problem will only vanish if either using a PN533V1.48 (in the RC-S330/360 reader) or if you do not allow the Nexus to become Initiator (using option "--mode initiator" with nfcpy examples).

Revision history for this message
guitar_dude (earlenceferns) said :
#10

>No surprise, there needs more to be changed. The Arygon reader requires a protocol mode byte at the beginning of every >command, which is "2" for plain TAM commands.
Yes, just read this in the datasheets.

>Likely that I'll push a new development branch out shortly and although my reader reports version 3.2 I guess that'll work with >yours as well.
Great! I think it should work.

>only vanish if either using a PN533V1.48 (in the RC-S330/360 reader) or if you do not allow the Nexus to become Initiator (using >option "--mode initiator" with nfcpy examples).
Even If the reader is the initiator, when the Nexus S replies with a message greater than 59 bytes, it will still fail right?

-Earlence

Revision history for this message
Stephen Tiedemann (stephen-tiedemann) said :
#11

Bazaar branch lp:~stephen-tiedemann/nfcpy/dev-arygon now works well with my Arygon module, obviously not extensively tested. Please check with your reader.

Large NDEF message transfer should work just fine if the reader takes the Initiator role, Nexus S as Target. This is regardless of which direction the message is going, i.e. where the NPP client and server are.

Revision history for this message
guitar_dude (earlenceferns) said :
#12

great work!
atleast something is happening now.

This is my output when I run npp-test-server:

earlence@earlence-Satellite-L650:~/nfcwork/dev-arygon/examples$ python npp-test-server.py
searching for a usb tty reader
trying reader at /dev/ttyUSB0
chipset is a PN532 version 1.6
missing ack frame from pn53x
Traceback (most recent call last):
  File "npp-test-server.py", line 191, in <module>
    main()
  File "npp-test-server.py", line 86, in main
    peer = llcp_connect(clf, general_bytes)
  File "npp-test-server.py", line 116, in llcp_connect
    peer = clf.poll(general_bytes)
  File "/home/earlence/nfcwork/dev-arygon/nfc/clf.py", line 69, in poll
    target = self.dev.poll(general_bytes)
  File "/home/earlence/nfcwork/dev-arygon/nfc/dev/pn53x.py", line 544, in poll
    target = poll()
  File "/home/earlence/nfcwork/dev-arygon/nfc/dev/pn53x.py", line 555, in poll_nfca
    rsp = self.dev.in_list_passive_target("106A", "")
  File "/home/earlence/nfcwork/dev-arygon/nfc/dev/pn53x.py", line 241, in in_list_passive_target
    rsp_data = self.command(0x4A, cmd_data, timeout=100)
  File "/home/earlence/nfcwork/dev-arygon/nfc/dev/pn53x.py", line 184, in command
    raise FrameError("lenght checksum error")
nfc.dev.pn53x.FrameError: [Errno -1] lenght checksum error

when I run llcp-test-server:
earlence@earlence-Satellite-L650:~/nfcwork/dev-arygon/examples$ ./llcp-test-server.py
searching for a usb tty reader
trying reader at /dev/ttyUSB0
chipset is a PN532 version 1.6
missing ack frame from pn53x
Traceback (most recent call last):
  File "./llcp-test-server.py", line 323, in <module>
    main()
  File "./llcp-test-server.py", line 238, in main
    peer = clf.poll(general_bytes)
  File "/home/earlence/nfcwork/dev-arygon/nfc/clf.py", line 69, in poll
    target = self.dev.poll(general_bytes)
  File "/home/earlence/nfcwork/dev-arygon/nfc/dev/pn53x.py", line 544, in poll
    target = poll()
  File "/home/earlence/nfcwork/dev-arygon/nfc/dev/pn53x.py", line 555, in poll_nfca
    rsp = self.dev.in_list_passive_target("106A", "")
  File "/home/earlence/nfcwork/dev-arygon/nfc/dev/pn53x.py", line 241, in in_list_passive_target
    rsp_data = self.command(0x4A, cmd_data, timeout=100)
  File "/home/earlence/nfcwork/dev-arygon/nfc/dev/pn53x.py", line 187, in command
    raise FrameError("invalid frame identifier")
nfc.dev.pn53x.FrameError: [Errno -1] invalid frame identifier

when I run llcp-test-client:

earlence@earlence-Satellite-L650:~/nfcwork/dev-arygon/examples$ ./llcp-test-client.py
searching for a usb tty reader
trying reader at /dev/ttyUSB0
chipset is a PN532 version 1.6
activated a p2p target in 424 kbps active mode
LLCP Link established, I'm the the DEP Initiator
Local LLCP Settings
  LLCP Version: 1.1
  Link Timeout: 500 ms
  Max Inf Unit: 1024 octet
  Service List: 0000000000000011
Remote LLCP Settings
  LLCP Version: 1.0
  Link Timeout: 1500 ms
  Max Inf Unit: 128 octet
  Service List: 0000000000000001
no test specified
shutdown on link disruption
I was the Initiator

and finally llcp-test-server:
earlence@earlence-Satellite-L650:~/nfcwork/dev-arygon/examples$ ./llcp-test-server.py
searching for a usb tty reader
trying reader at /dev/ttyUSB0
chipset is a PN532 version 1.6
activated a p2p target in 424 kbps active mode
LLCP Link established, I'm the the DEP Initiator
Local LLCP Settings
  LLCP Version: 1.1
  Link Timeout: 500 ms
  Max Inf Unit: 128 octet
  Service List: 0000000000000011
Remote LLCP Settings
  LLCP Version: 1.0
  Link Timeout: 1500 ms
  Max Inf Unit: 128 octet
  Service List: 0000000000000001
connectionless server bound to port 16
connectionmode server bound to port 17
connectionless server recv queue size is 2
connectionmode server recv window is 2
shutdown on link disruption
nfc.llcp.Error: [EPIPE] Broken pipe
remote side closed logical data link
close connless echo server socket
I was the Initiator

Cheers,
Earlence

Revision history for this message
guitar_dude (earlenceferns) said :
#13

ok...my bad. I did not use npp-test-server properly.

I used it like so:
python npp-test-server --mode=target --quirks=android and it worked.
This is my output:

trying reader at /dev/ttyUSB0
chipset is a PN532 version 1.6
activated as p2p target in 424 kbps passive mode
LLCP Link established, I'm the the DEP Target
Local LLCP Settings
  LLCP Version: 1.1
  Link Timeout: 1000 ms
  Max Inf Unit: 1024 octet
  Service List: 0000000000000011
Remote LLCP Settings
  LLCP Version: 1.0
  Link Timeout: 1500 ms
  Max Inf Unit: 128 octet
  Service List: 0000000000000001
npp server bound to port 16
accepting CONNECT from SAP 33
serving npp client on remote sap 33
ndef push server got message
d1012c546561726c656e63656561726c656e63656561726c656e63656561726c656e63656561726c656e63656561726c
  0000: d1 01 2c 54 65 61 72 6c 65 6e 63 65 65 61 72 6c ..,Tearlenceearl
  0010: 65 6e 63 65 65 61 72 6c 65 6e 63 65 65 61 72 6c enceearlenceearl
  0020: 65 6e 63 65 65 61 72 6c 65 6e 63 65 65 61 72 6c enceearlenceearl
NDEF records:
  [0] type = urn:nfc:wkt:T
  [0] name =
  [0] data = earlenceearlenceearlenceearlenceearlenceearl

Great work. thanks.
Now, I must try the initiator.

Revision history for this message
guitar_dude (earlenceferns) said :
#14

and yes! when nfcpy and the reader is in initiator mode, I can send even 70 bytes by ndef push from the nexus S!
you have been awesome! thanks for your time and help!

Revision history for this message
Stephen Tiedemann (stephen-tiedemann) said :
#15

Glad it works.

Not sure if you already found out by the "--help" option, if not:
- you can save the message from Nexus S into a file by "python npp-test-server.py > message.ndef"
- you can send a message to the Nexus S with "python npp-test-client.py < message.ndef"

Revision history for this message
guitar_dude (earlenceferns) said :
#16

thanks again!
you saved my life ;)

-Earlence