Skip to content

Commit

Permalink
Release version 2.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve O'Hara committed Apr 20, 2018
1 parent 7ddaff0 commit 1f7e4f9
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 36 deletions.
50 changes: 27 additions & 23 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## Version 2.0-rc1
* RxTxComm has been successfully replaced with jSerialComm and tested with RTU
* `RxTxComm` has been successfully replaced with `jSerialComm` and tested with RTU
* The whole codebase has been re-vamped to use modern constructs and practises, not a single class has remained untouched
* Codebase is compatible with JDK 1.6
* Javadoc has been extensively improved and fixed
Expand All @@ -14,15 +14,15 @@
* Build system incorporates GPG signing and is compatible with one-click deployment to Maven Central through Sonatype

## Version 2.0-rc2
* Added ability to specify timeout for Facade classes 'ModbusTCPMaster', 'ModbusUDPMaster' and 'ModbusSerialMaster'
* Added ability to specify timeout for Facade classes `ModbusTCPMaster`, `ModbusUDPMaster` and `ModbusSerialMaster`
* Fixed all the Unit ID checking when running as a Slave (myriad of problems - cannot see how it has ever worked)

## Version 2.0-rc3
* Fixed the timeouts for UDP/TCP and Serial listeners
* Added more test cases

## Version 2.0-rc4
* Fixed an issue with the TCPTransaction class not initialising the Transport correctly
* Fixed an issue with the `TCPTransaction` class not initialising the Transport correctly
* Removed all redundant casts
* Made Transport available from Facade classes so that listeners can be added for Serial events

Expand All @@ -38,16 +38,16 @@
* Removed duplicate request handling code
* Fix unit tests on linux #9 - thanks martentamerius
* Improved logging of errors and warnings with stack trace #10 - thanks martentamerius
* Facilitate multiple processimages in ModbusCoupler. #11 - thanks martentamerius
* WriteMultipleRegisters (Function Code : 0x10) does not work. #14 - chnaged use of signed shorts to unsigned
* Serial/RTU slower on 2.x #16 - worked around an issue with jSerialComm where setting timeouts on an open port injected a 200ms delay
* Facilitate multiple processimages in `ModbusCoupler`. #11 - thanks martentamerius
* WriteMultipleRegisters (Function Code : 0x10) does not work. #14 - changed use of signed shorts to unsigned
* Serial/RTU slower on 2.x #16 - worked around an issue with `jSerialComm` where setting timeouts on an open port injected a 200ms delay

## Version 2.1.1
* Corrected a problem with applying the timeouts when using the facade pattern

## Version 2.1.2
* Retrieve the localPort from opened socket if port is set to 0 #19
* CR characters lost on ModbusSerialTransport #18
* CR characters lost on `ModbusSerialTransport` #18
* Corrected timeout setting issues on serial ports and harmonised setting timeout with IP methods

## Version 2.1.3
Expand All @@ -56,57 +56,57 @@

## Version 2.2.0
* Modbus Slave Multiple Port Support #23
* Set ModbusCoupler to deprecated in favour of the new ModbusSlaveFactory and ModbusSlave sub-system
* Set `ModbusCoupler` to deprecated in favour of the new `ModbusSlaveFactory` and `ModbusSlave` sub-system
* Fixed some javadoc errors - thanks jan
* Timeout error on socket listener - thanks jan
* Now allows for slaves to share same socket but different protocols

## Version 2.2.1
* Amend TCPMasterConnection socket timeout handling #27 - thanks David
* Amend `TCPMasterConnection` socket timeout handling #27 - thanks David

## Version 2.2.2
* Fixed NPE in close method of SerialConnection if Comms port was never successfully opened
* Fixed NPE in close method of `SerialConnection` if Comms port was never successfully opened

## Version 2.3.0
* Adjusted write timers with fiddle factors to allow for idiosyncratic hardware
* jSerialComm library decoupled from implementation #28 - thanks Felipe
* `jSerialComm` library decoupled from implementation #28 - thanks Felipe

## Version 2.3.1
* Length of ReadWriteMultipleResponse indicates 1 byte too much? #31 - thanks elasticoder
* Length of `ReadWriteMultipleResponse` indicates 1 byte too much? #31 - thanks elasticoder
* Function code 0x17 first performs a read and then the write. #32 - thanks elasticoder
* Double socket creation in ModbusTCP. #33 - thanks stoorm5
* Double socket creation in `ModbusTCP`. #33 - thanks stoorm5

## Version 2.3.2
* Increased maximum queue length for incoming connections. #38 - thanks martentamerius
* Incorrect javadoc for ModbusSlaveFactory #35 - thanks bertrik
* Adds setRetries and setCheckingValidity services into ModbusTCPMaster #30 - thanks ericauguie
* Incorrect javadoc for `ModbusSlaveFactory` #35 - thanks bertrik
* Adds setRetries and `setCheckingValidity` services into `ModbusTCPMaster` #30 - thanks ericauguie
* Added RTU over TCP #43 - thanks eli-mcgowan
* Fixed setting timeout of TCPMaster does not get applied to transactions #41
* Fixed setting timeout of `TCPMaster` does not get applied to transactions #41
* Reduce an NPE - Serial port connection #40
* Fixed issue with serial write bytes delay if data bits not specified

## Version 2.3.3
* Specify IP address in ModbusSlaveFactory #46 - thanks MindVark
* Added getConnection() to AbstractSerialConnection - thanks nnadeau
* Specify IP address in `ModbusSlaveFactory` #46 - thanks MindVark
* Added `getConnection()` to `AbstractSerialConnection` - thanks nnadeau
* Reading full stream instead of parts - thanks liebehentze

## Version 2.3.4
* Fixed NullpointException at handleRequest in AbstractModbusListener #47
* Fixed NullpointException at handleRequest in `AbstractModbusListener` #47
* Add checks to see if serial port is available during connect #45

## Version 2.3.5
* Fixed a typo in the failure debug message
* Fixed the omission of the bit count when reading a DiscreteInput request
* Fixed the omission of the bit count when reading a `DiscreteInput` request

## Version 2.3.6
* Debug logger messages causing garbage collections even when DEBUG mode is not enabled #53
* RS485 echo in RTU mode #51 - thanks david

## Version 2.3.7
* Fixed a format error in the thrown connection retry catch block
* Propagate ModbusTCPListener timeout to the TCPSlaveConnection #59 - thanks javi
* Not possible to override handleRequest in ModbusSlave #57 - thanks javi
* Extending ModbusSlave exceptions list
* Propagate `ModbusTCPListener` timeout to the `TCPSlaveConnection` #59 - thanks javi
* Not possible to override `handleRequest` in `ModbusSlave` #57 - thanks javi
* Extending `ModbusSlave` exceptions list

## Version 2.3.8
* Added a sleep timer to the TCP/UDP/serial transaction retry loops
Expand All @@ -125,3 +125,7 @@
## Version 2.4.1
* Fixed some error messages
* Added more logging and made the TCP transaction a little more robust

## Version 2.4.2
* Fixed a critical issue with RTU over TCP when the connection is set to re-connecting.
Initial connection correctly uses `ModbusRTUTCPTransport` but subsequent connections use `ModbusTCPTransport` - RTU Over TCP Resend Bug #71
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<artifactId>j2mod</artifactId>
<name>j2mod</name>
<url>https://github.com/steveohara/j2mod</url>
<version>2.4.1</version>
<version>2.4.2</version>
<description>A fork of the j2mod library to support the jSerialComm connector</description>

<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public synchronized void execute() throws ModbusException {
if (!connection.isConnected()) {
try {
logger.debug("Connecting to: {}:{}", connection.getAddress().toString(), connection.getPort());
connection.connect(connection.getModbusTransport() instanceof ModbusRTUTCPTransport);
connection.connect();
transport = connection.getModbusTransport();
}
catch (Exception ex) {
Expand Down
52 changes: 41 additions & 11 deletions src/main/java/com/ghgande/j2mod/modbus/net/TCPMasterConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ public class TCPMasterConnection {

private ModbusTCPTransport transport;

private boolean useRtuOverTcp = false;

/**
* m_useUrgentData - sent a byte of urgent data when testing the TCP
* useUrgentData - sent a byte of urgent data when testing the TCP
* connection.
*/
private boolean m_useUrgentData = false;
private boolean useUrgentData = false;

/**
* Constructs a <tt>TCPMasterConnection</tt> instance with a given
Expand All @@ -75,7 +77,14 @@ public TCPMasterConnection(InetAddress adr) {
* @throws IOException if an I/O related error occurs.
*/
private void prepareTransport(boolean useRtuOverTcp) throws IOException {
if (transport == null) {

// If we don't have a transport, or the transport type has changed
if (transport == null || (this.useRtuOverTcp != useRtuOverTcp)) {

// Save the flag to tell us which transport type to use
this.useRtuOverTcp = useRtuOverTcp;

// Select the correct transport
if (useRtuOverTcp) {
logger.trace("prepareTransport() -> using RTU over TCP transport.");
transport = new ModbusRTUTCPTransport(socket);
Expand All @@ -100,7 +109,7 @@ private void prepareTransport(boolean useRtuOverTcp) throws IOException {
* @throws Exception if there is a network failure.
*/
public synchronized void connect() throws Exception {
connect(false);
connect(useRtuOverTcp);
}

/**
Expand Down Expand Up @@ -153,15 +162,15 @@ public synchronized boolean isConnected() {
}
else {
/*
* When m_useUrgentData is set, a byte of urgent data
* When useUrgentData is set, a byte of urgent data
* will be sent to the server to test the connection. If
* the connection is actually broken, an IException will
* occur and the connection will be closed.
*
* Note: RFC 6093 has decreed that we stop using urgent
* data.
*/
if (m_useUrgentData) {
if (useUrgentData) {
try {
socket.sendUrgentData(0);
ModbusUtil.sleep(5);
Expand Down Expand Up @@ -196,9 +205,6 @@ public void close() {
connected = false;
}
}

// Just in case users open it with a different protocol second time round (RTU over TCP)
transport = null;
}

/**
Expand Down Expand Up @@ -293,7 +299,7 @@ public void setAddress(InetAddress adr) {
* @return Status
*/
public boolean getUseUrgentData() {
return m_useUrgentData;
return useUrgentData;
}

/**
Expand All @@ -303,6 +309,30 @@ public boolean getUseUrgentData() {
* @param useUrgentData - Connections are testing using urgent data.
*/
public void setUseUrgentData(boolean useUrgentData) {
m_useUrgentData = useUrgentData;
this.useUrgentData = useUrgentData;
}

/**
* Returns true if this connection is an RTU over TCP type
*
* @return True if RTU over TCP
*/
public boolean isUseRtuOverTcp() {
return useRtuOverTcp;
}

/**
* Sets the transport type to use
* Normally set during the connection but can also be set after a connection has been established
*
* @param useRtuOverTcp True if the transport should be interpreted as RTU over tCP
*
* @throws Exception If the connection is not valid
*/
public void setUseRtuOverTcp(boolean useRtuOverTcp) throws Exception {
this.useRtuOverTcp = useRtuOverTcp;
if (isConnected()) {
prepareTransport(useRtuOverTcp);
}
}
}
37 changes: 37 additions & 0 deletions src/test/java/com/ghgande/j2mod/modbus/cmd/MasterReadTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
*
* Copyright (c) 2018, 4ng and/or its affiliates. All rights reserved.
* 4ENERGY PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*
*/
package com.ghgande.j2mod.modbus.cmd;

import com.ghgande.j2mod.modbus.facade.ModbusTCPMaster;
import com.ghgande.j2mod.modbus.procimg.Register;

/**
*
*/
public class MasterReadTest {

public static void main(String[] args) {
ModbusTCPMaster master = new ModbusTCPMaster("localhost", 502, 1000, true);
try {
master.connect(true);
for (int i = 0; i < 10; i++) {
int ref = 100;
Register[] regs = master.readMultipleRegisters(1, ref, 10);
for (Register reg : regs) {
System.out.printf("Reg: %d Val: %d\n", ref, reg.getValue());
ref++;
}
}
}
catch (Exception e) {
System.out.printf("ERROR - %s\n", e.getMessage());
}
finally {
master.disconnect();
}
}
}

0 comments on commit 1f7e4f9

Please sign in to comment.