Skip to content

feat: enhance Windows UART compatibility with platform-specific handling#13

Merged
wizzomafizzo merged 26 commits intomainfrom
fix/windows-uart-compatibility
Sep 17, 2025
Merged

feat: enhance Windows UART compatibility with platform-specific handling#13
wizzomafizzo merged 26 commits intomainfrom
fix/windows-uart-compatibility

Conversation

@wizzomafizzo
Copy link
Member

Summary

  • Add Windows-specific timeout adjustments (100ms vs 50ms) for better USB-to-serial driver compatibility
  • Implement Windows post-write delay (15ms) for proper buffer flushing
  • Add Windows port recovery mechanism for stuck COM port situations
  • Include comprehensive Windows-specific test coverage
  • Platform detection utilities for cross-platform handling

Problem Addressed

Windows USB-to-serial drivers have different timing characteristics compared to native UART or other platforms, which can cause:

  • Timeout issues with standard 50ms read timeouts
  • Buffer flushing problems without proper post-write delays
  • COM ports getting "stuck" requiring recovery mechanisms

Solution

This PR implements platform-specific handling that:

  1. Detects Windows platform and applies appropriate timing adjustments
  2. Increases read timeouts from 50ms to 100ms on Windows for stability
  3. Adds post-write delays to ensure proper buffer flushing on Windows
  4. Provides recovery mechanisms for stuck COM port scenarios
  5. Maintains compatibility with existing non-Windows behavior

Test Coverage

  • Windows platform detection tests
  • Timeout value verification for both Windows and non-Windows
  • Post-write delay timing verification
  • Port recovery mechanism validation
  • Integration function testing

Research & Best Practices

Implementation follows industry best practices for Windows COM port handling:

  • Timeout adjustments for Windows USB-to-serial drivers
  • Buffer management with drain/retry logic
  • Platform-specific timing accommodations
  • Graceful error handling and recovery

The go.bug.st/serial library (v1.6.4) provides additional capabilities like SetDTR(), SetRTS(), and buffer management methods that could be leveraged for future enhancements if specific issues arise.

Test plan

  • All existing tests pass
  • Windows-specific tests added and passing
  • Cross-platform compatibility maintained
  • No breaking changes to existing API

- Add Windows-specific timeout adjustments (100ms vs 50ms for other platforms)
- Implement Windows post-write delay for proper buffer flushing
- Add Windows port recovery mechanism for stuck COM port situations
- Include comprehensive Windows-specific test coverage
- Platform detection utilities for Windows vs other OS handling

Addresses Windows USB-to-serial driver timing differences and provides
recovery mechanisms for common Windows COM port issues.
…empty data

Critical fixes for Windows USB-serial driver compatibility:

- Add missing windowsPostWriteDelay() calls to all write operations (wakeUp, sendAck, sendNack, sendFrame)
- Reduce readRemainingData timeout from 2s to 500ms/750ms to prevent accumulation causing 30s delays
- Add windowsPortRecovery() calls on read errors with helper functions
- Implement platform-specific read timing (Windows: 2ms initial, 25ms retry vs Linux/Mac: 5ms, 50ms)
- Extract helper functions to reduce complexity and pass linting

Addresses root causes: timeout accumulation, missing USB-serial buffer flush delays,
and absent error recovery that were causing intermittent failures on Windows.
…iles

Enhance retry behavior with intelligent, command-specific retry profiles:
- ProfileDetection: Higher retry count for tag detection commands (5 attempts)
- ProfileDataExchange: Standard retry for data operations (3 attempts)
- ProfileStatus: Quick retry for status commands (2 attempts)
- ProfileDefault: General commands (3 attempts)

UART transport improvements:
- Command-specific timeouts for optimal performance
- Robust empty response recovery with escalating procedures
- Enhanced health monitoring system with periodic checks
- Comprehensive input buffer clearing to prevent stale data
- Windows-specific timing optimizations and port recovery
- Improved wake-up sequence with verification and double-wake pattern
- Better ACK waiting with configurable timeouts and retry logic

Fixes Windows UART timing issues and improves overall reliability.
@wizzomafizzo wizzomafizzo merged commit a3adaa8 into main Sep 17, 2025
8 checks passed
@wizzomafizzo wizzomafizzo deleted the fix/windows-uart-compatibility branch September 17, 2025 01:57
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