Fix IllegalArgumentException - #17
Open
da-Kai wants to merge 14 commits into
Open
Conversation
- Fix getCharIntervalMicro() to correctly return microseconds (was returning nanoseconds due to using NS_IN_A_MS instead of MICROS_IN_A_SEC) - Refactor SerialParameters constructors to use proper delegation (no-arg → full-arg chain) - Add baud rate validation (must be >= 1) to prevent division-by-zero in timing calculations - Rename DEFAULT_RS485_TX_DURING_RX to DEFAULT_RS485_RX_DURING_TX for clarity - Fix spurious Thread.currentThread().interrupt() calls on non-InterruptedException paths - Minor log message improvements for waitForTransmission
michaelgrill
approved these changes
Aug 13, 2026
- Replace thread priority manipulation with a hybrid wait strategy (sleep -> yield -> busy spin). - Anchor target end time dynamically using System.nanoTime() inside waitForTransmission. - Prevent thread starvation and reduce syscall overhead during sub-millisecond delays. - Improve IllegalArgumentException message in SerialParameters for invalid baud rate.
Align serial timing with MODBUS over Serial Line v1.02 by using a 750µs inter-character timeout for baud rates above 19200 and keeping 1750µs for inter-frame delay. Renames `getMaxCharDelay()` to `getMaxCharTimeout()` and updates RTU receive logic to use the correct timeout value. Also simplifies the nanos wait loop to sleep until close to target, then busy-wait for precise timing.
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.
Fix serial timing and refactor transmission delay handling
Changes:
nanosecond timeout value out of rangeexceptions in Thread.sleep()LONG_DELAY_FUDGE_FACTOR,SHORT_DELAY_FUDGE_FACTOR)getBitsPerCharacter()andgetStopBits()to AbstractSerialConnection