Topic: continuous scan hangs

I am working on a project that will scan a tag, do some stuff when a tag is found, then go back to scanning. I have tried the polling example, having infinite select on, and just scanning for a tag every second.

Scanning for a tag every second results in a segmentation fault at.
Infinite select just hangs after a minute or two.
Polling example hangs when if a pole continuously for too long

I am using a PN532 dev board, a raspberry pi running Raspbian, and a FTDI232 usb to serial adapter to connect the PN532 to the pi. I am writing the program in c.

I don't know if there is a problem with my implementation, the PN532, or something else. Any help would be greatly appreciated.

Here is my modified polling code.

nfc_init(&context);
  if (context == NULL) {
    ERR("Unable to init libnfc (malloc)");
    exit(EXIT_FAILURE);
  }

 
  
  while(1){
       pnd = nfc_open(context, NULL);

        if (pnd == NULL) {
          ERR("%s", "Unable to open NFC device.");
          nfc_exit(context);
          exit(EXIT_FAILURE);
        }

        if (nfc_initiator_init(pnd) < 0) {
          nfc_perror(pnd, "nfc_initiator_init");
          nfc_close(pnd);
          nfc_exit(context);
          exit(EXIT_FAILURE);
        }

        printf("NFC reader: %s opened\n", nfc_device_get_name(pnd));
      
        printf("NFC device will poll during %ld ms (%u pollings of %lu ms for %" PRIdPTR " modulations)\n", (unsigned long) uiPollNr * szModulations * uiPeriod * 150, uiPollNr, (unsigned long) uiPeriod * 150, szModulations);
        if ((res = nfc_initiator_poll_target(pnd, nmModulations, szModulations, uiPollNr, uiPeriod, &nt))  < 0) {
          nfc_perror(pnd, "nfc_initiator_poll_target");
          nfc_close(pnd);
          nfc_exit(context);
          exit(EXIT_FAILURE);
        }

        if (res > 0) {
          print_nfc_target(&nt, verbose);
          printf("Waiting for card removing...");
          while (0 == nfc_initiator_target_is_present(pnd, NULL)) {}
          nfc_perror(pnd, "nfc_initiator_target_is_present");
          printf("done.\n");
        } else {
          printf("No target found.\n");
        }
        nfc_close(pnd);
        sleep(1);
  }

  nfc_exit(context);
  exit(EXIT_SUCCESS);

Re: continuous scan hangs

So I've been playing around with it. There seems like there is a bug in the uart driver within libnfc. I have been running the same code, but with spi connection all night, and it is still responsive.

Re: continuous scan hangs

I ran my code with debugger. when it hangs, and I pause execution, it bring up line 324 in uart.c I unfortunately can't see the variables (my ide isn't setup correctly for that) so I don't know why it's breaking. I also don't know if I misconfigured something or if this is a bug, or even just incompatibility with the pi. I am wondering if I should submit a bug report or not.

here is the line that it is hang up on:

res = select(MAX(UART_DATA(sp)->fd, iAbortFd) + 1, &rfds, NULL, NULL, timeout ? &timeout_tv : NULL);

and here is my device configuration:

name = "Adafruit PN532 board via UART"
connstring = pn532_uart:/dev/ttyUSB0:115200

Re: continuous scan hangs

I found the problem. For some reason, the usb to serial converter was causing the issue. Swapped it with another convertor and it works perfectly now. Kind of odd.