steveohara / j2mod

Enhanced Modbus library implemented in the Java programming language
Apache License 2.0
276 stars 110 forks source link

Add support for explicitly configuring RS-485 mode #117

Closed sirhcel closed 3 years ago

sirhcel commented 3 years ago

jSerialComm added support for explicitly configuring the RS-485 mode of an interface on Linux a while ago. This does not introduce breaking changes to the API but always configures RS-485 mode via ioctl TIOCSRS485 which is off by default.

This breaks j2mod on Linux systems where the RS-485 mode of a serial interface is pre-configured at boot time and did not get touched afterwards. The following issues are likely surfacing phenomenons of that:

This PR adds the necessary configuration parameters to configure RS-485 mode explicitly from j2mod as well and allows to revive RS-485 operation. Our new configuration looks like

final SerialParameters result = new SerialParameters(
        portName,
        19200,
        AbstractSerialConnection.FLOW_CONTROL_DISABLED,
        AbstractSerialConnection.FLOW_CONTROL_DISABLED,
        8,
        AbstractSerialConnection.ONE_STOP_BIT,
        AbstractSerialConnection.EVEN_PARITY,
        false,
        // Here we come - the new parameters for configuring RS-485 mode:
        true,
        false,
        5000,
        2000);

using the newly added constructor for setting the four RS-485-related parameters as well. The already existing constructors set default values for the new RS-485 parameters and keep RS-485 mode disabled.

For correctly configuring the delay timing, https://github.com/Fazecast/jSerialComm/pull/353 is required for jSerialComm too.

steveohara commented 3 years ago

I've merged the changes into a 3.0.0 SNAPSHOT I'm looking at other fixes that I can add in before upgrading it to a full 3.0.0 release

pan-henryk commented 3 years ago

It did solve my problem! Thank you!