Skip to content

Commit

Permalink
Bumped log4j version for testing
Browse files Browse the repository at this point in the history
Added `isConnected()` method for al master facade classes #103
  • Loading branch information
Steve O'Hara committed Jul 2, 2020
1 parent 7a1c3ba commit f9f7256
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 4 deletions.
2 changes: 2 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,5 @@ _(**NOT BACKWARDS COMPATIBLE**)_
* Upgraded to jSeralcomm 2.6.2 that contains fix for [jSerialComm #277](https://github.com/Fazecast/jSerialComm/issues/277)
* Added some code cleanups as suggested by Sonar
* Fixed issue where slave listeners (TCP/UDP/Serial) fail silently if they cannot bind to a port
* Bumped log4j version for testing
* Added `isConnected()` method for al master facade classes #103
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.3</version>
<version>2.13.2</version>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,4 +550,11 @@ public synchronized void setCheckingValidity(boolean b) {
*/
public abstract AbstractModbusTransport getTransport();

/**
* Returns true if the master is connected
*
* @return True if connected
*/
public abstract boolean isConnected();

}
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,9 @@ public synchronized void setTimeout(int timeout) {
public AbstractModbusTransport getTransport() {
return connection == null ? null : connection.getModbusTransport();
}

@Override
public boolean isConnected() {
return connection != null && connection.isOpen();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class ModbusTCPMaster extends AbstractModbusMaster {

private final TCPMasterConnection connection;
private boolean reconnecting = false;
private boolean useRtuOverTcp = false;
private boolean useRtuOverTcp;

/**
* Constructs a new master facade instance for communication
Expand Down Expand Up @@ -189,4 +189,9 @@ public synchronized void setTimeout(int timeout) {
public AbstractModbusTransport getTransport() {
return connection == null ? null : connection.getModbusTransport();
}

@Override
public boolean isConnected() {
return connection != null && connection.isConnected();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,9 @@ public synchronized void setTimeout(int timeout) {
public AbstractModbusTransport getTransport() {
return connection == null ? null : connection.getModbusTransport();
}

@Override
public boolean isConnected() {
return connection != null && connection.isConnected();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ public void testCallback() {
((ModbusSerialTransport) master.getTransport()).removeListener(eventListener);
}

@Test
public void testIsConnected() {
assertTrue("Connected to serial master", master.isConnected());
}

private class EventListener extends AbstractSerialTransportListener {
int step;

Expand Down Expand Up @@ -269,5 +274,4 @@ public void afterResponseRead(AbstractSerialConnection port, ModbusResponse res)
step++;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ public void testBadUnitIdRequest() {
}
}


@Test
public void testReadDiscreteExtremeRequest() {
try {
Expand All @@ -182,4 +181,9 @@ public void testReadDiscreteExtremeRequest() {
}
}

@Test
public void testIsConnected() {
assertTrue("Connected to TCP master", master.isConnected());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,9 @@ public void testMasterReadMultipleHoldingRegisters() {
assertEquals("Failed to read multiple holding register 5 length 5", 4444, res.getRegisterValue(4));
}

@Test
public void testIsConnected() {
assertTrue("Connected to UDP master", master.isConnected());
}

}

0 comments on commit f9f7256

Please sign in to comment.