Open
Description
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:
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:
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