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]: PLC4X does not wait for response when reading data from Beckhoff Twincat 3 PLC with Ethernet/IP #1780

Open
2 of 16 tasks
JoonasC opened this issue Sep 23, 2024 · 4 comments
Labels
bug Ethernet/IP https://plc4x.apache.org/users/protocols/eip.html java Pull requests that update Java code

Comments

@JoonasC
Copy link

JoonasC commented Sep 23, 2024

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
@JoonasC JoonasC added the bug label Sep 23, 2024
@chrisdutz
Copy link
Contributor

Just a quick question ... why would you access a Beckhoff ADS device with EIP and not ADS? It's sort of like having a Porsche in the garage but driving with the Dacia ;-)

@JoonasC
Copy link
Author

JoonasC commented Sep 23, 2024

I'm investigating the Ethernet/IP functionality of PLC4X, but do not have any other Ethernet/IP capable devices on hand.

@chrisdutz
Copy link
Contributor

Hehe ... ok ... I guess that's really the only case it would make sense ;-)

As I also have a Beckhoff ADS device here ... if you could describe and document how to setup the EIP stuff, I could give it a try on my device.

@JoonasC
Copy link
Author

JoonasC commented Sep 23, 2024

Sure, here is Beckhoff's official documentation: https://infosys.beckhoff.com/english.php?content=../content/1033/tf6281_tc3_ethernetipscanner/index.html&id=

For a TLDR version:

  1. Add an Ethernet/IP scanner device:
    Screenshot from 2024-09-23 11-45-06
  2. Create a sync task for the device:
    Screenshot from 2024-09-23 11-48-57
  3. Create a global variable list called ETHIP, which contains variables declared in the M memory area:
    Screenshot from 2024-09-23 11-52-11
  4. Add the Tc2_EthernetIP library to the PLC project:
    Screenshot from 2024-09-23 12-02-35
  5. Check the read and write options for tags you want to read/write to:
    Screenshot from 2024-09-23 12-03-20
  6. Get the IP address of the Ethernet/IP server from the settings tab:
    Screenshot from 2024-09-23 12-05-43

@ottlukas ottlukas added java Pull requests that update Java code Ethernet/IP https://plc4x.apache.org/users/protocols/eip.html labels Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Ethernet/IP https://plc4x.apache.org/users/protocols/eip.html java Pull requests that update Java code
Projects
None yet
Development

No branches or pull requests

3 participants