Skip to content

Commit b6ebe2a

Browse files
authored
Add getters for config and transport in clients (#110)
1 parent 69f0b5d commit b6ebe2a

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

modbus/src/main/java/com/digitalpetri/modbus/client/ModbusClient.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ public abstract class ModbusClient {
3737
this.transport = transport;
3838
}
3939

40+
/**
41+
* Get the {@link ModbusClientTransport} used by this client.
42+
*
43+
* @return the {@link ModbusClientTransport} used by this client.
44+
*/
45+
public ModbusClientTransport<?> getTransport() {
46+
return transport;
47+
}
48+
4049
/**
4150
* Connect the underlying transport.
4251
*

modbus/src/main/java/com/digitalpetri/modbus/client/ModbusRtuClient.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,25 @@ public ModbusRtuClient(ModbusClientConfig config, ModbusRtuClientTransport trans
4646
transport.receive(this::onFrameReceived);
4747
}
4848

49+
/**
50+
* Get the {@link ModbusClientConfig} used by this client.
51+
*
52+
* @return the {@link ModbusClientConfig} used by this client.
53+
*/
54+
public ModbusClientConfig getConfig() {
55+
return config;
56+
}
57+
58+
/**
59+
* Get the {@link ModbusRtuClientTransport} used by this client.
60+
*
61+
* @return the {@link ModbusRtuClientTransport} used by this client.
62+
*/
63+
@Override
64+
public ModbusRtuClientTransport getTransport() {
65+
return transport;
66+
}
67+
4968
@Override
5069
public CompletionStage<ModbusResponsePdu> sendAsync(int unitId, ModbusRequestPdu request) {
5170
ByteBuffer pdu = ByteBuffer.allocate(256);

modbus/src/main/java/com/digitalpetri/modbus/client/ModbusTcpClient.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,25 @@ public ModbusTcpClient(ModbusClientConfig config, ModbusTcpClientTransport trans
4747
transport.receive(this::onFrameReceived);
4848
}
4949

50+
/**
51+
* Get the {@link ModbusClientConfig} used by this client.
52+
*
53+
* @return the {@link ModbusClientConfig} used by this client.
54+
*/
55+
public ModbusClientConfig getConfig() {
56+
return config;
57+
}
58+
59+
/**
60+
* Get the {@link ModbusTcpClientTransport} used by this client.
61+
*
62+
* @return the {@link ModbusTcpClientTransport} used by this client.
63+
*/
64+
@Override
65+
public ModbusTcpClientTransport getTransport() {
66+
return transport;
67+
}
68+
5069
public byte[] sendRaw(int unitId, byte[] pduBytes)
5170
throws ModbusExecutionException, ModbusResponseException, ModbusTimeoutException {
5271

0 commit comments

Comments
 (0)