windows平台修改libnfc 1.7.0使其支持pn532_uart模块
2013-04-08 19:15
399 查看
前几天写了一篇文章,详述了libnfc 1.7.0在windows下的编译过程,打开了对acr122u模块、pn53x_usb模块、pn532_uart模块等的支持,今天试了一下,发现在win下libnfc默认好像只扫描使用acr122_pcsc driver和pn53x_usb driver的模块,而我连接了pn532_uart模块之后提示没有找到NFC设备。
Debug模式编译运行nfc-list.exe输出如下:
unknown libnfc.general log_level is set to 3
debug libnfc.general allow_autoscan is set to true
debug libnfc.general allow_intrusive_scan is set to false
debug libnfc.general 0 device(s) defined by user
nfc-list.exe uses libnfc 1.7.0
debug libnfc.general 0 device(s) found using acr122_pcsc driver
debug libnfc.general 0 device(s) found using pn53x_usb driver
No NFC device found.
于是,我开始查找支持pn532_uart的方法,通过查看源码发现libnfc使用两种方式获取nfc设备:
1.自动扫描 autoscan
2.用户自定义设备 user_defined_device
libnfc支持读取libnfc.conf配置文件的方式加载用户定义的设备。
最开始,我尝试了在cmake生成的config.h里增加#define CONFFILES,重新编译的时候报错:
undefined reference to '_imp__regcomp'
这是由于conf.c里面调用了regcomp等函数,这些函数属于regex正则解析库,但是我使用的MinGW64里面没有这个库。
于是我复制了早期的MinGW的libregex库以及头文件,编译能通过,但是运行nfc-list.exe运行到读取配置文件时就出错退出了,估计还是正则库有问题。
libregex使用不了也没关系,其实可以修改conf.c去掉正则解析的过程,直接将参数赋值给nfc_context。
主要需要修改config.h和conf.c两个文件。
在config.h里增加 #define CONFFILES
修改conf.c如下:
重新编译,运行结果如下:
unknown libnfc.general log_level is set to 2
debug libnfc.general allow_autoscan is set to true
debug libnfc.general allow_intrusive_scan is set to false
debug libnfc.general 1 device(s) defined by user
debug libnfc.general #0 name: "chenxupro PN532", connstring: "pn532_uart:COM9:115200"
debug libnfc.general 0 device(s) found using acr122_pcsc driver
debug libnfc.general 0 device(s) found using pn53x_usb driver
debug libnfc.driver.pn532_uart Attempt to open: COM9 at 115200 bauds.
Try to Conf Key Value by chenxupro
nfc-list.exe uses libnfc 1.7.0
NFC device: pn532_uart:COM9 opened
1 ISO14443A passive target(s) found:
ISO/IEC 14443A (106 kbps) target:
ATQA (SENS_RES): 00 04
UID (NFCID1): 7d 88 c9 1d
SAK (SEL_RES): 08
Debug模式编译运行nfc-list.exe输出如下:
unknown libnfc.general log_level is set to 3
debug libnfc.general allow_autoscan is set to true
debug libnfc.general allow_intrusive_scan is set to false
debug libnfc.general 0 device(s) defined by user
nfc-list.exe uses libnfc 1.7.0
debug libnfc.general 0 device(s) found using acr122_pcsc driver
debug libnfc.general 0 device(s) found using pn53x_usb driver
No NFC device found.
于是,我开始查找支持pn532_uart的方法,通过查看源码发现libnfc使用两种方式获取nfc设备:
1.自动扫描 autoscan
2.用户自定义设备 user_defined_device
libnfc支持读取libnfc.conf配置文件的方式加载用户定义的设备。
最开始,我尝试了在cmake生成的config.h里增加#define CONFFILES,重新编译的时候报错:
undefined reference to '_imp__regcomp'
这是由于conf.c里面调用了regcomp等函数,这些函数属于regex正则解析库,但是我使用的MinGW64里面没有这个库。
于是我复制了早期的MinGW的libregex库以及头文件,编译能通过,但是运行nfc-list.exe运行到读取配置文件时就出错退出了,估计还是正则库有问题。
libregex使用不了也没关系,其实可以修改conf.c去掉正则解析的过程,直接将参数赋值给nfc_context。
主要需要修改config.h和conf.c两个文件。
在config.h里增加 #define CONFFILES
修改conf.c如下:
#include "conf.h" #ifdef HAVE_CONFIG_H # include "config.h" #endif // HAVE_CONFIG_H #ifdef CONFFILES #include <stdio.h> #include <stdlib.h> #include <dirent.h> #include <string.h> #include <regex.h> #include <sys/stat.h> #include <nfc/nfc.h> #include "nfc-internal.h" #include "log.h" #define LOG_CATEGORY "libnfc.config" #define LOG_GROUP NFC_LOG_GROUP_CONFIG #ifndef LIBNFC_SYSCONFDIR // If this define does not already exists, we build it using SYSCONFDIR #ifndef SYSCONFDIR #error "SYSCONFDIR is not defined but required." #endif // SYSCONFDIR #define LIBNFC_SYSCONFDIR SYSCONFDIR"/nfc" #endif // LIBNFC_SYSCONFDIR //#define LIBNFC_CONFFILE LIBNFC_SYSCONFDIR"/libnfc.conf" //#define LIBNFC_DEVICECONFDIR LIBNFC_SYSCONFDIR"/devices.d" #define LIBNFC_CONFFILE "libnfc.conf" #define LIBNFC_DEVICECONFDIR "devices.d" static bool conf_parse_file(const char *filename, void (*conf_keyvalue)(void *data), void *data) { printf("Try to Conf Key Value by chenxupro\n"); conf_keyvalue(data); return true; } static void conf_keyvalue_context(void *data) { nfc_context *context = (nfc_context *)data; //if (strcmp(key, "allow_autoscan") == 0) { string_as_boolean("true", &(context->allow_autoscan)); //} else if (strcmp(key, "allow_intrusive_scan") == 0) { string_as_boolean("false", &(context->allow_intrusive_scan)); //} else if (strcmp(key, "log_level") == 0) { context->log_level = atoi("2"); //} else if (strcmp(key, "device.name") == 0) { if ((context->user_defined_device_count == 0) || strcmp(context->user_defined_devices[context->user_defined_device_count - 1].name, "") != 0) { if (context->user_defined_device_count >= MAX_USER_DEFINED_DEVICES) { log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Configuration exceeded maximum user-defined devices."); return; } context->user_defined_device_count++; } strcpy(context->user_defined_devices[context->user_defined_device_count - 1].name, "chenxupro PN532"); //} else if (strcmp(key, "device.connstring") == 0) { if ((context->user_defined_device_count == 0) || strcmp(context->user_defined_devices[context->user_defined_device_count - 1].connstring, "") != 0) { if (context->user_defined_device_count >= MAX_USER_DEFINED_DEVICES) { log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Configuration exceeded maximum user-defined devices."); return; } context->user_defined_device_count++; } strcpy(context->user_defined_devices[context->user_defined_device_count - 1].connstring, "pn532_uart:COM9:115200"); } void conf_load(nfc_context *context) { conf_parse_file(LIBNFC_CONFFILE, conf_keyvalue_context, context); } #endif // CONFFILES
重新编译,运行结果如下:
unknown libnfc.general log_level is set to 2
debug libnfc.general allow_autoscan is set to true
debug libnfc.general allow_intrusive_scan is set to false
debug libnfc.general 1 device(s) defined by user
debug libnfc.general #0 name: "chenxupro PN532", connstring: "pn532_uart:COM9:115200"
debug libnfc.general 0 device(s) found using acr122_pcsc driver
debug libnfc.general 0 device(s) found using pn53x_usb driver
debug libnfc.driver.pn532_uart Attempt to open: COM9 at 115200 bauds.
Try to Conf Key Value by chenxupro
nfc-list.exe uses libnfc 1.7.0
NFC device: pn532_uart:COM9 opened
1 ISO14443A passive target(s) found:
ISO/IEC 14443A (106 kbps) target:
ATQA (SENS_RES): 00 04
UID (NFCID1): 7d 88 c9 1d
SAK (SEL_RES): 08
相关文章推荐
- windows平台使用cmake编译libnfc 1.7.0 rc6全过程
- windows平台使用cmake编译libnfc 1.7.0 rc6全过程
- windows下python安装Numpy、Scipy、matplotlib模块
- Windows平台上修改某个文件的创建、访问、修改日期时间属性
- 教你pomeloclient包libpomelo增加cocos2d-x 3.0工程(Windows、Android、IOS平台)
- 信息系统开发平台OpenExpressApp - 报表模块支持ReportObjectView
- OpenNMS二次开发,支持Windows平台?
- windows平台下编译curl支持https
- Qt5.5.0在Windows下静态编译(修改参数以后才能支持XP)good
- windows平台下的进程内存修改
- error MSB8008: 指定的平台工具集(Windows7.1SDK)未安装或无效。请确保选择受支持的 PlatformToolset 值。
- 信息系统开发平台OpenExpressApp - 报表模块支持ReportObjectView
- GuiLite-全平台UI框架(目前已经支持: iOS,Android, Linux, Windows,Mac,VR)
- Python非官方扩展模块搜索方法(尤其是Windows平台下已编译好的模块)
- Toradex 为基于NXP i.MX7的计算机模块提供Windows Embedded Compact 操作系统支持
- Windows平台视频录制支持视频并列模式录制
- 如何使 vlc 支持 fdk-aac 编码(windows平台
- 一个修改过的python zifile的包装模块,支持对目录压缩(包括空的文件夹),解压缩会解压缩空目录
- 在Windows平台上安装Node.js及NPM模块管理
- Jpeglib移植到arm平台 & 修改支持解码内存中的jpeg数据流