NFCPY:安全退出beam.py示例
我下载了nfcpy,并成功运行了beam examples。我用beam.py
这个程序把数据从一个装有PN532 NFC芯片的树莓派发送到一部Nexus安卓手机,数据发送得很顺利,但只要我把手机放在读卡器旁边,树莓派上的这个python脚本就会消失。这个问题是关于如何使用nfcpy进行发送和接收的。我该怎么做才能让beam.py
安全地存在呢?
示例:
发送:
./beam.py --device tty:AMA0:pn53x send ndef start.ndef
[nfc.clf] searching for reader with path 'tty:AMA0:pn53x'
[nfc.clf] using NXP PN532 at /dev/ttyAMA0
[nfc.snep.server] snep server bound to port 4 (MIU=1984, RW=15), will accept up to 1048576 byte NDEF messages
[nfc.dev.pn53x] activated as target in 424 kbps active mode
[nfc.dev.pn53x] [Errno 110] Connection timed out
[nfc.dev.pn53x] activated a p2p target in 424 kbps active mode
[nfc.llcp.llc] LLCP Link established as NFC-DEP Initiator
Local LLCP Settings
LLCP Version: 1.1
Link Timeout: 500 ms
Max Inf Unit: 2175 octet
Service List: 0000000000010011
Remote LLCP Settings
LLCP Version: 1.1
Link Timeout: 1500 ms
Max Inf Unit: 128 octet
Service List: 0000000000010011
[nfc.dev.pn53x] [PN53x Error 0x13] Format error during RF communication
接收:
./beam.py --device tty:AMA0:pn53x recv print
[nfc.clf] searching for reader with path 'tty:AMA0:pn53x'
[nfc.clf] using NXP PN532 at /dev/ttyAMA0
[nfc.snep.server] snep server bound to port 4 (MIU=1984, RW=15), will accept up to 1048576 byte NDEF messages
[nfc.dev.pn53x] activated as target in 424 kbps active mode
[nfc.dev.pn53x] [Errno 110] Connection timed out
[nfc.dev.pn53x] activated a p2p target in 424 kbps active mode
[nfc.llcp.llc] LLCP Link established as NFC-DEP Initiator
Local LLCP Settings
LLCP Version: 1.1
Link Timeout: 500 ms
Max Inf Unit: 2175 octet
Service List: 0000000000010011
Remote LLCP Settings
LLCP Version: 1.1
Link Timeout: 1500 ms
Max Inf Unit: 128 octet
Service List: 0000000000010011
[nfc.llcp.tco] accepting CONNECT from SAP 32
[nfc.snep.server] serving snep client on remote sap 32
[main] default snep server got put request
[main] print ndef message 'application/com.example.android.beam'
record 1
type = 'application/com.example.android.beam'
name = ''
data = 'Beam me up!\n\nBeam Time: 15:11:22\n'
record 2
type = 'urn:nfc:ext:android.com:pkg'
name = ''
data = 'com.example.android.beam'
[nfc.dev.pn53x] [PN53x Error 0x13] Format error during RF communication
1 个回答
1
NFC点对点连接最自然的结束方式是因为某种错误导致连接中断。只要两个设备靠得很近,它们之间的通信就会持续进行,互相交换数据包。这样,任意一个设备都可以随时开始其他的对话,SNEP(或称为“传送”)并不是唯一的选择。
针对nfcpy的传送示例,如果想要提前结束连接,可以按Ctrl-C键。或者可以修改示例,让它在任务完成后自动结束。