libnfc源码编译与使用

libnfc是GNU公共许可正下公布的第一个免费的底层的NFC开发包和编程API,可以作为了解PN532使用流程的一个很好的途径。下面先从libnfc的安装说起。源码需自行从官网下载。

环境

Ubuntu18.04+libusb-latest+libnfc-latest

安装依赖
 

sudo apt install libudev-dev autoconf automake libtool libusb-dev dh-autoreconf libusb-0.1.4 pkg-config

编译

// libnfc source root
./autoreconf -Wall -vis
./configure --with-drivers=pn532_uart --enable-serial-autoprobe --prefix=/usr/local/
make 
sudo make install

使用

1、获取nfc设备列表

./nfc-list
# 注意,libnfc使用需要root权限,除非赋予当前用户/dev/ttyUSB0的读写权限

如报错需要将/usr/local/lib加入LD_LIBRARY_PATH

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib

2、修改libnfc配置文件,打印串口数据和PN532帧信息

# Allow device auto-detection (default: true)
# Note: if this auto-detection is disabled, user has to set manually a device
# configuration using file or environment variable
#allow_autoscan = true

# Allow intrusive auto-detection (default: false)
# Warning: intrusive auto-detection can seriously disturb other devices
# This option is not recommended, user should prefer to add manually his device.
#allow_intrusive_scan = false

# Set log level (default: error)
# Valid log levels are (in order of verbosity): 0 (none), 1 (error), 2 (info), 3 (debug)
# Note: if you compiled with --enable-debug option, the default log level is "debug"
###################### hear #################################
log_level = 3

# Manually set default device (no default)
# To set a default device, you must set both name and connstring for your device
# Note: if autoscan is enabled, default device will be the first device available in device list.
device.name = "microBuilder.eu"
device.connstring = "pn532_uart:/dev/ttyUSB0"

PN532输出如下,就可以根据PN532的输出进行流程分析了。 

debug	libnfc.chip.pn53x	SetParameters
debug	libnfc.bus.uart	TX: 00 00 ff 03 fd d4 12 14 06 00 
debug	libnfc.bus.uart	RX: 00 00 ff 00 ff 00 
debug	libnfc.chip.pn53x	PN53x ACKed
debug	libnfc.bus.uart	RX: 00 00 ff 02 fe 
debug	libnfc.bus.uart	RX: d5 13 
debug	libnfc.bus.uart	RX: 18 00 

debug	libnfc.chip.pn53x	WriteRegister
debug	libnfc.bus.uart	TX: 00 00 ff 08 f8 d4 08 63 02 80 63 03 80 59 00 
debug	libnfc.bus.uart	RX: 00 00 ff 00 ff 00 
debug	libnfc.chip.pn53x	PN53x ACKed
debug	libnfc.bus.uart	RX: 00 00 ff 02 fe 
debug	libnfc.bus.uart	RX: d5 09 
debug	libnfc.bus.uart	RX: 22 00 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值