Skip to content

Fix IllegalArgumentException - #17

Open
da-Kai wants to merge 14 commits into
developmentfrom
feature/fix-illegal-argument-exception
Open

Fix IllegalArgumentException#17
da-Kai wants to merge 14 commits into
developmentfrom
feature/fix-illegal-argument-exception

Conversation

@da-Kai

@da-Kai da-Kai commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Fix serial timing and refactor transmission delay handling

Changes:

  • Fix nanosecond timeout value out of range exceptions in Thread.sleep()
  • Fix serial throughput calculation by including start bit and fix end-bit retreval
  • Extract sleep fudge factors into named constants (LONG_DELAY_FUDGE_FACTOR, SHORT_DELAY_FUDGE_FACTOR)
  • Add getBitsPerCharacter() and getStopBits() to AbstractSerialConnection
  • Add baud rate validation (>= 1) to prevent division-by-zero
  • Refactor SerialParameters constructors to use proper delegation chain
  • Rename DEFAULT_RS485_TX_DURING_RX → DEFAULT_RS485_RX_DURING_TX for clarity

grafik

make shure milli and nano values are in range
@da-Kai
da-Kai requested review from Copilot and removed request for Copilot July 31, 2026 06:54

This comment was marked as outdated.

da-Kai added 4 commits August 11, 2026 12:34
* move `getBitsPerCharacter` to `AbstractSerialConnection`
* fix stopBits value

This comment was marked as outdated.

This comment was marked as outdated.

da-Kai added 2 commits August 12, 2026 20:46
- 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
@da-Kai
da-Kai requested a review from michaelgrill August 13, 2026 11:40

@michaelgrill michaelgrill left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 (only some minor comments)

Comment thread src/main/java/com/ghgande/j2mod/modbus/io/ModbusSerialTransport.java Outdated
Comment thread src/main/java/com/ghgande/j2mod/modbus/util/SerialParameters.java Outdated
da-Kai added 3 commits August 13, 2026 20:24
- 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.
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.

3 participants