Skip to content

Add RS-485 configuration parameters for serial transports#146

Merged
kevinherron merged 1 commit into
masterfrom
rs485-config
Mar 14, 2026
Merged

Add RS-485 configuration parameters for serial transports#146
kevinherron merged 1 commit into
masterfrom
rs485-config

Conversation

@kevinherron
Copy link
Copy Markdown
Contributor

Summary

  • Add rtsActiveHigh, termination, rxDuringTx, delayBefore, and delayAfter fields to SerialPortTransportConfig for fine-grained RS-485 control (Linux setRs485ModeParameters)
  • When rs485Mode is enabled, both client and server transports now call setRs485ModeParameters() with the configured values
  • Include builder methods, Javadoc, and a test for default/custom RS-485 configuration

Test plan

  • Rs485ConfigTest verifies default values and custom builder configuration
  • Manual verification on Linux with an RS-485 adapter

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.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 SerialPortTransportConfig with additional RS-485 tuning parameters (RTS polarity, termination, RX-during-TX, delays).
  • Apply RS-485 mode parameters to SerialPort in 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.

@kevinherron kevinherron added this to the 2.1.5 milestone Mar 14, 2026
@kevinherron kevinherron merged commit abb7d2e into master Mar 14, 2026
7 checks passed
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.

2 participants