diff --git a/README.md b/README.md index e3a1440a..b9971eed 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Snapshot releases can be downloaded here # Dependencies * [jSerialComm](http://fazecast.github.io/jSerialComm/) -The serial comms is handled by JSerialComm that includs native implementations for most platforms. +The serial comms is handled by JSerialComm that includes native implementations for most platforms. * [slf4j](https://www.slf4j.org/) Logging facade to fit in with your application logging framework * JRE 1.8 (JRE 1.6 for v2.70 and lower) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 3b702379..60fadb9f 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -256,6 +256,8 @@ _(**NOT BACKWARDS COMPATIBLE**)_ * Add support for providing an optional java.net proxy for. (#151) * Added support for testing serial comms on Mac/Linux -## Version 3.2.2-openems.1 -* Add Deploy Workflow -* Forward 'disablePortConfiguration'-setting from jSerialComm \ No newline at end of file +## Version 3.2.3 +* Failed to read response! CRC Error in received frame #153 - thanks thomas-hutterer-tik. (#153) +* Expose disableRs485ModeControl from jSerialComm v2.11.4 thanks da-Kai (#160) + +**_Note: - from 3.3.0 onwards, the release notes will be maintained in commit and GitHub releases._** diff --git a/_config.yml b/_config.yml new file mode 100644 index 00000000..2f7efbea --- /dev/null +++ b/_config.yml @@ -0,0 +1 @@ +theme: jekyll-theme-minimal \ No newline at end of file diff --git a/pom.xml b/pom.xml index 2a01a3ff..0338c544 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ j2mod j2mod https://github.com/OpenEMS/j2mod - 3.2.2-openems.2 + 3.3.0-openems.1-SNAPSHOT A Modbus TCP/UDP/Serial Master and Slave implementation bundle @@ -23,7 +23,7 @@ Dieter Wimberger wimpi@user.sourceforge.com SourceForge - http://jamod.sourceforge.net + https://jamod.sourceforge.net architect developer @@ -34,7 +34,7 @@ John Charlton jdcharlton@user.sourceforge.com SourceForge - http://jamod.sourceforge.net + https://jamod.sourceforge.net developer @@ -42,9 +42,9 @@ jhaugh Julie Haugh - http://www.ghgande.com + https://www.ghgande.com greenHouse Gas and Electric - http://www.ghgande.com + https://www.ghgande.com developer @@ -54,7 +54,7 @@ Steve O'Hara steve.ohara@4ng.co.uk 4NG - http://www.4ng.co.uk + https://www.4ng.co.uk developer @@ -64,7 +64,7 @@ The Apache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt + https://www.apache.org/licenses/LICENSE-2.0.txt @@ -88,15 +88,14 @@ org.slf4j - slf4j-log4j12 + slf4j-reload4j 2.0.9 - test org.apache.logging.log4j log4j-core - 2.20.0 + 2.25.3 test @@ -252,7 +251,7 @@ org.sonatype.central central-publishing-maven-plugin - 0.7.0 + 0.9.0 true central diff --git a/src/main/java/com/ghgande/j2mod/modbus/io/BytesOutputStream.java b/src/main/java/com/ghgande/j2mod/modbus/io/BytesOutputStream.java index 65af0fc4..068b9b56 100644 --- a/src/main/java/com/ghgande/j2mod/modbus/io/BytesOutputStream.java +++ b/src/main/java/com/ghgande/j2mod/modbus/io/BytesOutputStream.java @@ -70,6 +70,17 @@ public void reset() { count = 0; } + /** + * Resets this BytesInputStream using the given + * byte[] as new input buffer. + * + * @param data a byte array with data to be read. + */ + public void reset(byte[] data) { + buf = data; + count = 0; + } + @Override public void writeBoolean(boolean v) throws IOException { dataOutputStream.writeBoolean(v); diff --git a/src/main/java/com/ghgande/j2mod/modbus/io/ModbusRTUTransport.java b/src/main/java/com/ghgande/j2mod/modbus/io/ModbusRTUTransport.java index 3d513215..a36a3d2b 100644 --- a/src/main/java/com/ghgande/j2mod/modbus/io/ModbusRTUTransport.java +++ b/src/main/java/com/ghgande/j2mod/modbus/io/ModbusRTUTransport.java @@ -321,7 +321,8 @@ protected ModbusRequest readRequestIn(AbstractModbusListener listener) throws Mo int[] crc = ModbusUtil.calculateCRC(inBuffer, 0, dlength); // does not include CRC if (ModbusUtil.unsignedByteToInt(inBuffer[dlength]) != crc[0] || ModbusUtil.unsignedByteToInt(inBuffer[dlength + 1]) != crc[1]) { if (logger.isDebugEnabled()) { - logger.debug("CRC should be {}, {}", Integer.toHexString(crc[0]), Integer.toHexString(crc[1])); + logger.debug("CRC should be {}, {} inBuffer={}", Integer.toHexString(crc[0]), Integer.toHexString(crc[1]), + ModbusUtil.toHex(inBuffer, 0, dlength + 2)); } // Drain the input in case the frame was misread and more @@ -380,6 +381,8 @@ protected ModbusRequest readRequestIn(AbstractModbusListener listener) throws Mo logger.debug("Read message not meant for us: {}", ModbusUtil.toHex(byteInputOutputStream.getBuffer(), 0, byteInputOutputStream.size())); } } + // as the buffer might have been bumped due to more than 256 bytes input, we reset it to the original inBuffer + byteInputOutputStream.reset(inBuffer); } } } diff --git a/src/main/java/com/ghgande/j2mod/modbus/io/ModbusSerialTransport.java b/src/main/java/com/ghgande/j2mod/modbus/io/ModbusSerialTransport.java index fb20f333..317beb81 100644 --- a/src/main/java/com/ghgande/j2mod/modbus/io/ModbusSerialTransport.java +++ b/src/main/java/com/ghgande/j2mod/modbus/io/ModbusSerialTransport.java @@ -637,7 +637,8 @@ int getInterFrameDelay() { return 1750; } else { - return Math.max(getCharInterval(Modbus.INTER_MESSAGE_GAP), Modbus.MINIMUM_TRANSMIT_DELAY); + long delay = Math.max(getCharIntervalMicro(Modbus.INTER_MESSAGE_GAP), Modbus.MINIMUM_TRANSMIT_DELAY * 1000L); + return delay > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) delay; } } @@ -660,17 +661,6 @@ long getMaxCharDelay() { * Used for message timings. * * @param chars Number of characters - * @return char interval in milliseconds - */ - int getCharInterval(double chars) { - return (int) (getCharIntervalMicro(chars) / 1000); - } - - /** - * Calculates an interval based on a set number of characters. - * Used for message timings. - * - * @param chars Number of caracters * @return microseconds */ long getCharIntervalMicro(double chars) { diff --git a/src/main/java/com/ghgande/j2mod/modbus/msg/ReadFileRecordRequest.java b/src/main/java/com/ghgande/j2mod/modbus/msg/ReadFileRecordRequest.java index 32bfbdeb..dece9283 100644 --- a/src/main/java/com/ghgande/j2mod/modbus/msg/ReadFileRecordRequest.java +++ b/src/main/java/com/ghgande/j2mod/modbus/msg/ReadFileRecordRequest.java @@ -19,7 +19,6 @@ import com.ghgande.j2mod.modbus.msg.ReadFileRecordResponse.RecordResponse; import com.ghgande.j2mod.modbus.net.AbstractModbusListener; import com.ghgande.j2mod.modbus.procimg.*; -import com.ghgande.j2mod.modbus.procimg.Record; import java.io.DataInput; import java.io.DataOutput; diff --git a/src/main/java/com/ghgande/j2mod/modbus/msg/WriteFileRecordRequest.java b/src/main/java/com/ghgande/j2mod/modbus/msg/WriteFileRecordRequest.java index ec6f9dc5..912f2679 100644 --- a/src/main/java/com/ghgande/j2mod/modbus/msg/WriteFileRecordRequest.java +++ b/src/main/java/com/ghgande/j2mod/modbus/msg/WriteFileRecordRequest.java @@ -19,7 +19,6 @@ import com.ghgande.j2mod.modbus.msg.WriteFileRecordResponse.RecordResponse; import com.ghgande.j2mod.modbus.net.AbstractModbusListener; import com.ghgande.j2mod.modbus.procimg.*; -import com.ghgande.j2mod.modbus.procimg.Record; import java.io.DataInput; import java.io.DataOutput; diff --git a/src/main/java/com/ghgande/j2mod/modbus/net/TCPMasterConnection.java b/src/main/java/com/ghgande/j2mod/modbus/net/TCPMasterConnection.java index 3720dc84..e6d34b3e 100644 --- a/src/main/java/com/ghgande/j2mod/modbus/net/TCPMasterConnection.java +++ b/src/main/java/com/ghgande/j2mod/modbus/net/TCPMasterConnection.java @@ -322,6 +322,7 @@ public void setNetworkInterface(NetworkInterface networkInterface) { /** * Sets the Proxy that this socket uses. If null (the default), no proxy is used. + * @param proxy the proxy as Proxy. */ public void setProxy(Proxy proxy) { if(socket != null && proxy != null) { diff --git a/src/main/java/com/ghgande/j2mod/modbus/slave/ModbusSlaveFactory.java b/src/main/java/com/ghgande/j2mod/modbus/slave/ModbusSlaveFactory.java index 2c7d6483..381fb984 100644 --- a/src/main/java/com/ghgande/j2mod/modbus/slave/ModbusSlaveFactory.java +++ b/src/main/java/com/ghgande/j2mod/modbus/slave/ModbusSlaveFactory.java @@ -197,6 +197,7 @@ public static synchronized void close() { /** * Returns the running slave listening on the given port * + * @param type Type of slave * @param port Port to check for running slave * @return Null or ModbusSlave */ @@ -207,6 +208,7 @@ public static synchronized ModbusSlave getSlave(ModbusSlaveType type, int port) /** * Returns the running slave listening on the given port * + * @param type Type of slave * @param port Port to check for running slave * @return Null or ModbusSlave */ diff --git a/src/main/java/com/ghgande/j2mod/modbus/util/SerialParameters.java b/src/main/java/com/ghgande/j2mod/modbus/util/SerialParameters.java index 83d28f2d..ca5601ac 100644 --- a/src/main/java/com/ghgande/j2mod/modbus/util/SerialParameters.java +++ b/src/main/java/com/ghgande/j2mod/modbus/util/SerialParameters.java @@ -395,29 +395,6 @@ public void setDatabits(String databits) { } } - /** - * Disables RS-485 control signals management. - *

- * Please note that this is only effective on Linux. - *

- * This function forces RS-485 mode to stay untouched, - * regardless of the current setting of RS-485 mode. - *

- * 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 String. * @@ -924,6 +901,29 @@ public void setRs485DelayAfterTxMicroseconds(String microseconds) { setRs485DelayAfterTxMicroseconds(Integer.parseInt(microseconds)); } + /** + * Disables RS-485 control signals management. + *

+ * Please note that this is only effective on Linux. + *

+ * This function forces RS-485 mode to stay untouched, + * regardless of the current setting of RS-485 mode. + *

+ * 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; + } + @Override public String toString() { return "SerialParameters{" + diff --git a/src/test/java/com/ghgande/j2mod/modbus/TestModbusTCPMasterEquality.java b/src/test/java/com/ghgande/j2mod/modbus/TestModbusTCPMasterEquality.java index 424e2837..2b15b9c0 100644 --- a/src/test/java/com/ghgande/j2mod/modbus/TestModbusTCPMasterEquality.java +++ b/src/test/java/com/ghgande/j2mod/modbus/TestModbusTCPMasterEquality.java @@ -9,7 +9,6 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.*; /** * Testing class for {@link ModbusTCPMaster#equals} & {@link ModbusTCPMaster#hashCode} methods diff --git a/src/test/java/com/ghgande/j2mod/modbus/cmd/TCPSlaveTest.java b/src/test/java/com/ghgande/j2mod/modbus/cmd/TCPSlaveTest.java index 27769029..964bb628 100644 --- a/src/test/java/com/ghgande/j2mod/modbus/cmd/TCPSlaveTest.java +++ b/src/test/java/com/ghgande/j2mod/modbus/cmd/TCPSlaveTest.java @@ -16,7 +16,6 @@ package com.ghgande.j2mod.modbus.cmd; import com.ghgande.j2mod.modbus.Modbus; -import com.ghgande.j2mod.modbus.procimg.Record; import com.ghgande.j2mod.modbus.procimg.*; import com.ghgande.j2mod.modbus.slave.ModbusSlave; import com.ghgande.j2mod.modbus.slave.ModbusSlaveFactory; diff --git a/src/test/java/com/ghgande/j2mod/modbus/cmd/UDPSlaveTest.java b/src/test/java/com/ghgande/j2mod/modbus/cmd/UDPSlaveTest.java index ee0d759b..9910a0a1 100644 --- a/src/test/java/com/ghgande/j2mod/modbus/cmd/UDPSlaveTest.java +++ b/src/test/java/com/ghgande/j2mod/modbus/cmd/UDPSlaveTest.java @@ -17,7 +17,6 @@ import com.ghgande.j2mod.modbus.Modbus; import com.ghgande.j2mod.modbus.procimg.*; -import com.ghgande.j2mod.modbus.procimg.Record; import com.ghgande.j2mod.modbus.slave.ModbusSlave; import com.ghgande.j2mod.modbus.slave.ModbusSlaveFactory; import org.slf4j.Logger; diff --git a/src/test/java/com/ghgande/j2mod/modbus/utils/AbstractTestModbus.java b/src/test/java/com/ghgande/j2mod/modbus/utils/AbstractTestModbus.java index 2e223c70..f9d7e655 100644 --- a/src/test/java/com/ghgande/j2mod/modbus/utils/AbstractTestModbus.java +++ b/src/test/java/com/ghgande/j2mod/modbus/utils/AbstractTestModbus.java @@ -16,7 +16,6 @@ package com.ghgande.j2mod.modbus.utils; import com.ghgande.j2mod.modbus.procimg.*; -import com.ghgande.j2mod.modbus.procimg.Record; import com.ghgande.j2mod.modbus.slave.ModbusSlave; import com.ghgande.j2mod.modbus.util.Observable; import com.ghgande.j2mod.modbus.util.Observer;