禁用pn53x_check_communication:输入/输出错误消息

时间:2018-01-12 17:26:56

标签: c lib-nfc

我正在使用用c编译的libnfc 1.7.1来读取Raspberry Pi上的PN532阅读器。目标是为Node-RED创建一个节点,该节点注入扫描卡的UID或沿库或读取器传递错误。我修改了示例,将卡的UID作为唯一的正常输出。当无法加载库时,我无法打印除错误之外的任何内容,无法连接读卡器时出现错误或卡的UID。我在/etc/nfc/libnfc.conf中将日志级别更改为0,但我的程序仍在打印“pn53x_check_communication:输入/输出错误”(不需要的)以及“错误:无法打开NFC设备”。 (想要)我找不到任何方法来禁用I / O错误消息。我查看了库,发现this返回NFC_EIO,这是我得到的I / O错误,但无法找到它实际打印的任何地方。没有修改库我找不到任何方法来禁用此打印。如果没有什么可以做的,我可以编程我的节点忽略这个输出,但我宁愿消除它。我的代码如下:

#include <stdlib.h>
#include <nfc/nfc.h>

static void
print_long(const uint8_t *pbtData, const size_t szBytes)
{
  size_t  szPos;

  for (szPos = 0; szPos < szBytes; szPos++) {
    printf("%03lu", pbtData[szPos]);
  }
  printf("\n");
}

int
main(int argc, const char *argv[])
{
  nfc_device *pnd;
  nfc_target nt;

  // Allocate only a pointer to nfc_context
  nfc_context *context;

  // Initialize libnfc and set the nfc_context
  nfc_init(&context);
  if (context == NULL) {
    printf("Unable to init libnfc (malloc)\n");
    exit(EXIT_FAILURE);
  }

  // Open, using the first available NFC device which can be in order of selection:
  //   - default device specified using environment variable or
  //   - first specified device in libnfc.conf (/etc/nfc) or
  //   - first specified device in device-configuration directory (/etc/nfc/devices.d) or
  //   - first auto-detected (if feature is not disabled in libnfc.conf) device
  pnd = nfc_open(context, NULL);

  //Send error
  if (pnd == NULL) {
    printf("ERROR: %s\n", "Unable to open NFC device.");
    exit(EXIT_FAILURE);
  }

  // Set opened NFC device to initiator mode
  if (nfc_initiator_init(pnd) < 0) {
    nfc_perror(pnd, "nfc_initiator_init");
    exit(EXIT_FAILURE);
  }

  while(true){
    // Poll for a ISO14443A (MIFARE) tag
    const nfc_modulation nmMifare = {
      .nmt = NMT_ISO14443A,
      .nbr = NBR_106,
    };

    //Print decimal version of UID and wait until it's removed to scan again
    if (nfc_initiator_select_passive_target(pnd, nmMifare, NULL, 0, &nt) > 0) {
      print_long(nt.nti.nai.abtUid, nt.nti.nai.szUidLen);
      while (0 == nfc_initiator_target_is_present(pnd, NULL)) {}
    }
  }
}

0 个答案:

没有答案