JoonasC opened a new issue, #1780:
URL: https://github.com/apache/plc4x/issues/1780

   ### 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:
   ```java
   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](https://github.com/user-attachments/assets/13bf2710-e28a-4c19-b4b7-99083be96e0a)
   
   
[Capture.pcapng.gz](https://github.com/user-attachments/files/17098250/Capture.pcapng.gz)
   
   I can workaround this bug by adding a manual `Thread.sleep` before trying to 
interact with the read response object:
   ```java
   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](https://github.com/user-attachments/assets/a9a16252-2ff1-46c6-866c-7486dbc8b3bd)
   
   ### Version
   
   0.12.0
   
   ### Programming Languages
   
   - [X] plc4j
   - [ ] plc4go
   - [ ] plc4c
   - [ ] plc4net
   
   ### Protocols
   
   - [ ] AB-Ethernet
   - [ ] ADS /AMS
   - [ ] BACnet/IP
   - [ ] CANopen
   - [ ] DeltaV
   - [ ] DF1
   - [X] EtherNet/IP
   - [ ] Firmata
   - [ ] KNXnet/IP
   - [ ] Modbus
   - [ ] OPC-UA
   - [ ] S7


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to