feat: add pn532killer support - #2
Open
treyturner wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hey @spiercey! I started using this script before I recognized you from
plexamp-tui, cheers for another great idea.I picked up a PN532Killer to play with, but it wasn't immediately recognized by this script. They enumerate as CDC serial devices and require different DTR/RTS states than a typical PN532 USB-UART adapter. Applying them conditionally can add PN532Killer support without changing existing behavior.
Note that I only have a wired PN532Killer and not the BLE version, so I stopped short of updating the README with explicit support.
Summary
Adds (wired) PN532Killer support while preserving compatibility with standard PN532 USB-UART readers.
serial.tools.list_ports1a86:55d3/dev/ttyUSB*or/dev/ttyACM*InCommunicateThruand CRC-AMotivation
The PN532Killer presents several compatibility differences from a standard PN532 UART reader:
/dev/ttyACM0, rather than/dev/ttyUSB0.InDataExchangeNTAG reads, but doesn't return the requested data. Its supported raw-card path usesInCommunicateThruwith an appended ISO14443A CRC.These issues prevented the reader from reading Plexamp tags.
Implementation
Reader discovery
Serial ports are enumerated using
serial.tools.list_ports, allowing access to USB metadata such as product name, description, VID, and PID.A positively identified PN532Killer is preferred. Generic
/dev/ttyUSB*devices remain the fallback for standard PN532 USB-UART adapters, followed by generic/dev/ttyACM*devices.Serial configuration
PN532Killer ports are opened with:
These states are configured before opening the port. Standard PN532 readers retain pySerial’s existing defaults.
No-card polling
The custom reader class treats a valid
InListPassiveTargetresponse containing zero targets as a normal no-card result:This prevents unnecessary reader reconnections and preserves errors for genuinely unexpected target counts.
PN532Killer NTAG reads
Standard Adafruit NTAG reads use
InDataExchange, but the PN532Killer only acknowledges those commands without returning data.For PN532Killer devices, NTAG reads now:
READcommand for the requested page.InCommunicateThru.Standard PN532 readers continue using Adafruit’s existing
InDataExchangeimplementation.Testing
Validated with both a standard PN532 USB-UART adapter and a PN532Killer.
/dev/ttyUSB0/dev/ttyACM0Nonewithout reconnectingInCommunicateThrusuccessfully reads NTAG pages04e3c36cce2a81from physical hardware