Skip to content

[Bug]: PLC4X does not wait for response when reading data from Beckhoff Twincat 3 PLC with Ethernet/IP #1780

Open
@JoonasC

Description

@JoonasC

What happened?

It seems like PLC4X does not wait for a response from the Ethernet/IP server when reading data (specifically using the Ethernet/IP scanner device in Beckhoff Twincat3 PLCs)

I'm using the following code to test reading:

public class Main {
  public static void main(String[] args) {
    String connectionString = "eip://10.50.100.216:44818?bigEndian=false";

    try (PlcConnection plcConnection = PlcDriverManager.getDefault().getConnectionManager().getConnection(connectionString)) {
      PlcReadRequest.Builder readBuilder = plcConnection.readRequestBuilder();
      readBuilder.addTagAddress("Var1", "%Var1");
      PlcReadRequest readRequest = readBuilder.build();
      System.out.println("--- Reading data ---");
      PlcReadResponse readResponse = readRequest.execute().get();
      System.out.println("--- Read complete ---");
      System.out.println(readResponse.getResponseCode("Var1"));
      System.out.println(readResponse.getObject("Var1"));
    } catch (Exception e) {
      System.out.println("Connection failed");
      e.printStackTrace();
    }
  }
}

Stacktrace:

org.apache.plc4x.java.api.exceptions.PlcInvalidTagException: Var1 invalid
at org.apache.plc4x.java.spi.messages.DefaultPlcReadResponse.getResponseCode(DefaultPlcReadResponse.java:100)
at org.example.Main.main(Main.java:20)

Looking at Wireshark, PLC4X closes the connection before the PLC has a chance to respond to the read request:
image

Capture.pcapng.gz

I can workaround this bug by adding a manual Thread.sleep before trying to interact with the read response object:

System.out.println("--- Reading data ---");
PlcReadResponse readResponse = readRequest.execute().get();
Thread.sleep(1000);
System.out.println("--- Read complete ---");

Here is my Twincat3 Ethernet/IP explicit messaging configuration:
image

Version

0.12.0

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Ethernet/IPhttps://plc4x.apache.org/users/protocols/eip.htmljavaPull requests that update Java code

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions