Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Modbus Rtu/Ascii ping always fail #1724

Open
2 of 16 tasks
dasoops opened this issue Aug 9, 2024 · 0 comments
Open
2 of 16 tasks

[Bug]: Modbus Rtu/Ascii ping always fail #1724

dasoops opened this issue Aug 9, 2024 · 0 comments
Labels
bug java Pull requests that update Java code Modbus https://plc4x.apache.org/users/protocols/modbus.html

Comments

@dasoops
Copy link

dasoops commented Aug 9, 2024

What happened?

Execute this code

public class ModbusRtuPingTest {
    @Test
    void testPing() throws Exception {
        var connection = PlcDriverManager.getDefault().getConnectionManager().getConnection("modbus-rtu:tcp://localhost:502");
        Assertions.assertDoesNotThrow(() -> connection.ping().join());
    }
}

Then

org.opentest4j.AssertionFailedError: Unexpected exception thrown: java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "tag" is null

	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:152)
	at org.junit.jupiter.api.AssertDoesNotThrow.createAssertionFailedError(AssertDoesNotThrow.java:84)
	at org.junit.jupiter.api.AssertDoesNotThrow.assertDoesNotThrow(AssertDoesNotThrow.java:75)
	at org.junit.jupiter.api.AssertDoesNotThrow.assertDoesNotThrow(AssertDoesNotThrow.java:58)
	at org.junit.jupiter.api.Assertions.assertDoesNotThrow(Assertions.java:3228)
	at org.apache.plc4x.java.modbus.rtu.ModbusRtuPingTest.testPing(ModbusRtuPingTest.java:30)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1597)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1597)
Caused by: java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "tag" is null
	at org.apache.plc4x.java.modbus.base.protocol.ModbusProtocolLogic.getReadRequestPdu(ModbusProtocolLogic.java:149)
	at org.apache.plc4x.java.modbus.rtu.protocol.ModbusRtuProtocolLogic.ping(ModbusRtuProtocolLogic.java:68)
	at org.apache.plc4x.java.spi.connection.AbstractPlcConnection.ping(AbstractPlcConnection.java:183)
	at org.apache.plc4x.java.spi.messages.DefaultPlcPingRequest.execute(DefaultPlcPingRequest.java:40)
	at org.apache.plc4x.java.spi.connection.DefaultNettyPlcConnection.ping(DefaultNettyPlcConnection.java:205)
	at org.apache.plc4x.java.modbus.rtu.ModbusRtuPingTest.lambda$0(ModbusRtuPingTest.java:30)
	at org.junit.jupiter.api.AssertDoesNotThrow.assertDoesNotThrow(AssertDoesNotThrow.java:71)
	... 6 more

The pingAddress attribute of ModbusRtuProtocolLogic seems to have never been assigned, which is different from ModbusTcpProtocolLogic.

@Override
public void setConfiguration(ModbusRtuConfiguration configuration) {
this.requestTimeout = Duration.ofMillis(configuration.getRequestTimeout());
this.unitIdentifier = (short) configuration.getDefaultUnitIdentifier();
this.defaultPayloadByteOrder = configuration.getDefaultPayloadByteOrder();
this.tm = new RequestTransactionManager(1);
}

Furthermore, its ModbusRtuProtocolLogic.ping() and ModbusRtuDriver.canPing() are both overridden, so I think this is unexpected.

@Override
public CompletableFuture<PlcPingResponse> ping(PlcPingRequest pingRequest) {
CompletableFuture<PlcPingResponse> future = new CompletableFuture<>();

@Override
protected boolean canPing() {
return true;
}

Additionally, ModbusAsciiProtocolLogic also seems to have this issue.

Version

v0.12.0, v0.13.0-SNAPSHOT

Programming Languages

  • plc4j
  • plc4go
  • plc4c
  • plc4net

Protocols

  • AB-Ethernet
  • ADS /AMS
  • BACnet/IP
  • CANopen
  • DeltaV
  • DF1
  • EtherNet/IP
  • Firmata
  • KNXnet/IP
  • Modbus
  • OPC-UA
  • S7
@dasoops dasoops added the bug label Aug 9, 2024
@ottlukas ottlukas added java Pull requests that update Java code Modbus https://plc4x.apache.org/users/protocols/modbus.html labels Aug 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug java Pull requests that update Java code Modbus https://plc4x.apache.org/users/protocols/modbus.html
Projects
None yet
Development

No branches or pull requests

2 participants