Add RS-485 configuration parameters for serial transports#146
Merged
Conversation
Add rtsActiveHigh, termination, rxDuringTx, delayBefore, and delayAfter parameters to SerialPortTransportConfig. When rs485Mode is enabled, both client and server transports now call setRs485ModeParameters() with these values.
There was a problem hiding this comment.
Pull request overview
Adds full RS-485 parameter support to the serial transport configuration and applies those settings to the underlying jSerialComm SerialPort, with tests validating both config defaults/customization and transport application.
Changes:
- Extend
SerialPortTransportConfigwith additional RS-485 tuning parameters (RTS polarity, termination, RX-during-TX, delays). - Apply RS-485 mode parameters to
SerialPortin both client and server transports when RS-485 mode is enabled. - Add unit tests covering defaults, custom values, and transport-to-SerialPort parameter propagation.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
modbus-serial/src/main/java/com/digitalpetri/modbus/serial/SerialPortTransportConfig.java |
Adds new RS-485 configuration fields + builder setters and documentation. |
modbus-serial/src/main/java/com/digitalpetri/modbus/serial/client/SerialPortClientTransport.java |
Applies RS-485 parameters to the SerialPort when enabled. |
modbus-serial/src/main/java/com/digitalpetri/modbus/serial/server/SerialPortServerTransport.java |
Applies RS-485 parameters to the SerialPort when enabled. |
modbus-serial/src/test/java/com/digitalpetri/modbus/serial/Rs485ConfigTest.java |
Introduces tests for RS-485 config defaults/custom values and transport application via reflection. |
Comments suppressed due to low confidence (2)
modbus-serial/src/main/java/com/digitalpetri/modbus/serial/client/SerialPortClientTransport.java:80
- The catch-all exception handler wraps failures from both getCommPort and subsequent configuration calls (e.g., setComPortParameters / setRs485ModeParameters), but the message says "failed to get comm port". This will be misleading if configuration fails. Consider updating the error message (or splitting try/catch) to reflect that port configuration may be the failing step.
this.serialPort = sp;
} catch (Exception e) {
throw new ModbusException(
"failed to get comm port '%s'".formatted(config.serialPort()), e);
}
modbus-serial/src/main/java/com/digitalpetri/modbus/serial/server/SerialPortServerTransport.java:88
- The exception message here says "failed to get comm port", but this try block now also includes port configuration (setComPortParameters / setRs485ModeParameters). If configuration throws, the message will point readers at the wrong root cause. Please adjust the message or split error handling so failures are reported accurately.
this.serialPort = sp;
} catch (Exception e) {
throw new ModbusException(
"failed to get comm port '%s'".formatted(config.serialPort()), e);
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
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.
Summary
rtsActiveHigh,termination,rxDuringTx,delayBefore, anddelayAfterfields toSerialPortTransportConfigfor fine-grained RS-485 control (LinuxsetRs485ModeParameters)rs485Modeis enabled, both client and server transports now callsetRs485ModeParameters()with the configured valuesTest plan
Rs485ConfigTestverifies default values and custom builder configuration