Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<dependency>
<groupId>com.fazecast</groupId>
<artifactId>jSerialComm</artifactId>
<version>2.10.4</version>
<version>2.11.4</version>
</dependency>

<dependency>
Expand Down
20 changes: 2 additions & 18 deletions src/main/java/com/ghgande/j2mod/modbus/net/SerialConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public class SerialConnection extends AbstractSerialConnection {
private SerialPort serialPort;
private InputStream inputStream;
private int timeout = Modbus.DEFAULT_TIMEOUT;
private boolean disablePortConfiguration = false;

/**
* Default constructor
Expand Down Expand Up @@ -167,8 +166,8 @@ private void applyConnectionParameters() {

// Set connection parameters, if set fails return parameters object to original state
if (serialPort != null) {
if (this.disablePortConfiguration) {
serialPort.disablePortConfiguration();
if (parameters.isRs485ControlDisabled()) {
serialPort.disableRs485ModeControl();
}
serialPort.setComPortParameters(parameters.getBaudRate(), parameters.getDatabits(), parameters.getStopbits(), parameters.getParity());
serialPort.setFlowControl(parameters.getFlowControlIn() | parameters.getFlowControlOut());
Expand Down Expand Up @@ -278,19 +277,4 @@ public Set<String> getCommPorts() {
}
return returnValue;
}

/**
* Disables the library from calling any of the underlying device driver
* configuration methods.
*
* <p>
* This function should never be called except in very specific cases involving
* USB-to-Serial converters with buggy device drivers.
* </p>
*
* @see SerialPort#disablePortConfiguration()
*/
public void disablePortConfiguration() {
disablePortConfiguration = true;
}
}
26 changes: 26 additions & 0 deletions src/main/java/com/ghgande/j2mod/modbus/util/SerialParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
*/
public class SerialParameters {

private static final boolean DEFAULT_RS485_DISABLE_CONTROL = false;
private static final boolean DEFAULT_RS485_MODE = false;
private static final boolean DEFAULT_RS485_TX_ENABLE_ACTIVE_HIGH = true;
private static final boolean DEFAULT_RS485_ENABLE_TERMINATION = false;
Expand All @@ -57,6 +58,7 @@ public class SerialParameters {
private boolean rs485RxDuringTx;
private int rs485DelayBeforeTxMicroseconds;
private int rs485DelayAfterTxMicroseconds;
private boolean rs485DisableControl;

/**
* Constructs a new <tt>SerialParameters</tt> instance with
Expand All @@ -80,6 +82,7 @@ public SerialParameters() {
rs485TxEnableActiveHigh = DEFAULT_RS485_TX_ENABLE_ACTIVE_HIGH;
rs485DelayBeforeTxMicroseconds = DEFAULT_RS485_DELAY_BEFORE_TX_MICROSECONDS;
rs485DelayAfterTxMicroseconds = DEFAULT_RS485_DELAY_AFTER_TX_MICROSECONDS;
rs485DisableControl = DEFAULT_RS485_DISABLE_CONTROL;
}

/**
Expand Down Expand Up @@ -392,6 +395,29 @@ public void setDatabits(String databits) {
}
}

/**
* Disables RS-485 control signals management.
* <p>
* <i>Please note that this is only effective on Linux.</i>
* <p>
* This function forces RS-485 mode to stay untouched,
* regardless of the current setting of RS-485 mode.
* <p>
* This function is necessary for Linux drivers that don't handle TIOCGRS485 properly.
*/
public void disableRs485Control() {
this.rs485DisableControl = true;
}

/**
* Returns whether RS-485 control signals management is disabled.
*
* @return true if RS-485 control signals management is disabled.
*/
public boolean isRs485ControlDisabled() {
return this.rs485DisableControl;
}

/**
* Returns the number of data bits as <tt>String</tt>.
*
Expand Down