Skip to content

ntag2xx_read_block() should return None on failure #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jerryneedell opened this issue Feb 13, 2022 · 0 comments · Fixed by #53
Closed

ntag2xx_read_block() should return None on failure #52

jerryneedell opened this issue Feb 13, 2022 · 0 comments · Fixed by #53
Assignees

Comments

@jerryneedell
Copy link
Contributor

jerryneedell commented Feb 13, 2022

A Discord user reported this error: https://discord.com/channels/327254708534116352/537365702651150357/942511372028223538

    cardReadValues = (pn532.ntag2xx_read_block(6))
    cardRead = int.from_bytes((cardReadValues), "big")
    print("Reading! This is Card", (cardRead), "!")
    audio.play(sounds[cardRead])
    
    while audio.playing:
        pass
    print("stopped")

Here's the bit of code, and here's the error

Traceback (most recent call last):
  File "code.py", line 73, in <module>
  File "/lib/adafruit_pn532/adafruit_pn532.py", line 497, in ntag2xx_read_block
TypeError: 'NoneType' object isn't subscriptable

The problem was the card was being removed too quickly, but the function should return none rather than throw an error according to the doctoring:

    def ntag2xx_read_block(self, block_number):
        """Read a block of data from the card.  Block number should be the block
        to read.  If the block is successfully read a bytearray of length 16 with
        data starting at the specified block will be returned.  If the block is
        not read then None will be returned.
``` at 
https://github.com/adafruit/Adafruit_CircuitPython_PN532/blob/main/adafruit_pn532/adafruit_pn532.py#L490

If it returned None, the user could test for None before using the result.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant