Skip to content

fix: add stabilization delay to prevent write failures (error 0x27)#40

Merged
wizzomafizzo merged 2 commits intomainfrom
fix/write-stabilization-delay
Jan 20, 2026
Merged

fix: add stabilization delay to prevent write failures (error 0x27)#40
wizzomafizzo merged 2 commits intomainfrom
fix/write-stabilization-delay

Conversation

@wizzomafizzo
Copy link
Member

Summary

  • Add 75ms stabilization delay in executeWriteToTag before attempting write operations
  • Add error code 0x27 to IsRFError() so it's retryable via existing retry logic
  • Add test case for 0x27 error classification

Problem

When using WriteToNextTag from zaparoo-core, writes frequently fail with error 0x27 ("wrong context for command") on the first attempt but succeed after retrying. This occurs because:

  1. InListPassiveTarget detects the tag AND selects it as target 1
  2. executeWriteToTag is called immediately (no stabilization delay)
  3. If the card was still being positioned when detected, the RF field becomes unstable
  4. The target selection is lost due to RF communication disruption
  5. SendDataExchange fails with 0x27 because target 1 is no longer valid

Solution

The stabilization delay matches the existing pattern in tagops.InitFromDetectedTag and prevents most 0x27 errors. Classifying 0x27 as an RF error enables retries for any remaining edge cases.

Test plan

  • All existing tests pass (make check)
  • New test case added for 0x27 error classification
  • Manual test with zaparoo-core write API

When using WriteToNextTag, writes frequently fail with error 0x27 ("wrong
context for command") on the first attempt. This occurs because the card
may still be moving when detected, causing RF field instability that makes
the PN532 lose target selection.

Changes:
- Add 75ms stabilization delay in executeWriteToTag before attempting write
- Add error code 0x27 to IsRFError() so it's retryable via existing logic
- Add test case for 0x27 error classification

The stabilization delay matches the existing pattern in tagops.InitFromDetectedTag
and prevents most 0x27 errors. Classifying 0x27 as an RF error enables retries
for any remaining edge cases.
@codecov
Copy link

codecov bot commented Jan 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@wizzomafizzo wizzomafizzo merged commit ba0968e into main Jan 20, 2026
12 checks passed
@wizzomafizzo wizzomafizzo deleted the fix/write-stabilization-delay branch January 20, 2026 10:16
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 this pull request may close these issues.

1 participant